How can I save 3d arrays in a cell array?

조회 수: 9 (최근 30일)
Miriã  Gollmann
Miriã Gollmann 2018년 6월 16일
댓글: Walter Roberson 2018년 6월 16일
I have two 3d arrays (138x155x24) but I can't put it in only cell array. How can I do that?
Thanks for any help!
  댓글 수: 2
James Tursa
James Tursa 2018년 6월 16일
You certainly can put 3D arrays into a cell array. Please post what variables you have and also post the code you are currently trying, and what you want to get as a result.
Miriã  Gollmann
Miriã Gollmann 2018년 6월 16일
Sorry, I forgot.
I have seven days with hours values of wind velocity. This variable has 24 data array (lon x lat), with dimension longitude x latitude x hours.
My problem is: Using ncread, save arrays of wind velocity (lon x lat) in X-axis (u) and Y-axis (v) in a cell array. Each line have to show the 24 matrix of data of one day.

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

채택된 답변

Walter Roberson
Walter Roberson 2018년 6월 16일
data = cell(1,2);
for K = 1 : 2
data{K} = rand(138, 155, 24);
end
and now data is a cell array with two entries, each containing a 138 x 155 x 24 array.
  댓글 수: 2
Miriã  Gollmann
Miriã Gollmann 2018년 6월 16일
Thank you!
Should I use exactly this command?
And do you know how can I plot it?
Walter Roberson
Walter Roberson 2018년 6월 16일
dinfo = dir('*.nc');
nfile = length(dinfo);
data = cell(nfile, 1);
for K = 1 : nfile
thisfile = dinfo(K).name;
data{K} = mat2cell( ncread(thisfile, 'velocity'), 3 ); %split on 3rd dimension
end
This would give you a cell array, data, with one entry per file. Each entry would itself be a cell array of length 24, each containing one lon x lat entry.
Note: you might find that you get lat x lon entries instead of lon x lat. If so then
data{K} = mat2cell( permute(ncread(thisfile, 'velocity'), [2 1 3], 3 ); %split on 3rd dimension

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by