Stacking 2D matrix to 3D using time as a third variable
이전 댓글 표시
Hi I am a beginner in matlab and I am trying to stack 2D matrix into 3D matrix. I have variable sst as 1440*720 and time variable as 1*366. These are all daily data. How do I stack time to sst so that I have 366*1440*720 matrix. I have tried using cat and meshgrid but nothing seems to work. Thank you.
data.time = cat(3,data.time,data.sst)
or
[data.sst1]=meshgrid(data.sst,data.time); (this multiplies 1440*720 and gives me 366*1036800 matrix)
댓글 수: 3
Voss
2022년 12월 9일
To end up with a 366*1440*720 array, you would need 366 individual 1440*720 matrices. In other words, you need a 1440*720 matrix for each time value. But it seems that you have one 1440*720 matrix and one scalar for each time value.
Put another way: a 366*1440*720 array has 366*1440*720 = 379,468,800 elements, but you have 366 + 1440*720 = 1,037,166 elements, not enough for a 366*1440*720 array.
If you had 366 individual 1440*720 matrices, then you could stack (and reshape/permute) them into a 366*1440*720 array (or a 1440*720*366 array, or whatever, as long as there's still 379,468,800 elements), but it doesn't seem like that's what you have.
Peter Perkins
2022년 12월 12일
Just out of curiousity ...
366, OK, days in 2020 (although you may have a bug when you work on a non-leap year)
1440, OK, so maybe 24*60 minutes in a day?
What does 720 represent?
Or is 1440x720 a spatial lat/lon grid?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 App Building에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!