matlab

Classified in Language

Written at on English with a size of 2.25 KB.

 

Consider the following Matrix named Temp, which contains the monthly average temperature during the period of 2005-2009.

>> A=[12 10 11 13 8; 10 11 13 14 7; 15 14 16 14 12; 18 21 22 19 20;22 22 24 20 21;26 27 28 25 28;27 29 30 29 30;28 28 29 27 28; 20 23 24 22 22;19 21 19 18 19;14 13 14 12 10;11 9 10 10 9]

A =

12 10 11 13 8

10 11 13 14 7

15 14 16 14 12

18 21 22 19 20

22 22 24 20 21

26 27 28 25 28

27 29 30 29 30

28 28 29 27 28

20 23 24 22 22

19 21 19 18 19

14 13 14 12 10

11 9 10 10 9

Write the Matlab commands to do the following operations:

1. The average temperature in 2008 saved in Average_2008.

>>Average_2008= mean(A(:,4))

ans =

18.5833

2. The vector of the average temperatures in the summer months (July, August and September) during 2005-2009 and save it Average_Summer.

>> July= mean(A(7,:))

July =29

>> August= mean(A(8,:))

August =28

>> September= mean(A(9,:))

September =22.2000

>> c=[July August September]

c =29.0000 28.0000 22.2000

>> mean(c)

ans =26.4000

>> Average_Summer=mean(c)

Average_Summer =26.4000

3. The average temperature in February during 2005-2009 and save it Average_February.

>> Average_February= mean(A(2,:))

Average_February =11

4. The number of months of 2009 in which the temperature was above 20 °C and save it Hot_2009.

>> Hot_2009=A(:,5)>20

Hot_2009 = 0

0

0

0

1

1

1

1

1

0

0

0

>> Hot_2009=sum(A(:,5)>20)

Hot_2009 =5

Entradas relacionadas: