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!