What is the difference between working with matrix and array?

I have a data where the first dimension is month, the second dimension is city, and the third dimension is a vector of temperature of the city in that month. it is 12 (months) * 10 (cities) * 30 (temperature). Is it easier to work with a 120*30 matrix or with a 12*10*30 array?

댓글 수: 7

Is it easier to work with a 120*30 matrix or with a 12*10*30 array?
To do what ?
Why not a 120-by-3 table where the first two variables are the month and city data and the third contains 120 1-by-30 vectors of temperature data?
alpedhuez
alpedhuez 2022년 7월 15일
편집: alpedhuez 2022년 7월 15일
120*30 I assume.
I presume the 30 temperatures are for day of month, regularizing out the irregular/inconvenient variable number of days/month?
If that were the case, I'd add the day of month as the fourth variable and create the table with month, day, city, temperature.
"120*30 I assume."
No, with @Steven Lord's idea, each record in the table will have a 1x30 array of temperatures. The problem with that is still have to index into the array to get individual values -- may be ok if all one cares about is statistical measures that are computable from the array like mean, min, max, etc., ... But, if want to do something by the day, then the division as suggested above would be easier.
FYI your usage of * as a separate between dimension sizes usually takes me take a second to interpret. If you say your matrix is size 120*30 does that mean that size returns [120 30] or does it mean you called something like zeros(120*30) to preallocate it?
I'd advise using either "size [120 30]", "120-by-30", or "120 x 30". Or you could copy and paste from the Command Window display, which uses × instead of either * or x.
@dpb, if the plan is to analyze the data based on time and/or days, storing it as a timetable may be useful.
Thank you for all the comments.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2022a

태그

질문:

2022년 7월 15일

댓글:

2022년 7월 15일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by