How to put the numbers of cell array in a new cell array

2 views (last 30 days)
Hi,
Actually I have defined a cell "B" (1*3 cell). As the each cell array of "B" is defined for the numbers of the cast number (i.e., B{1,1} is 1043x1 cell, B{1,2} is 18x1 cell, B{1,3} is 397x1 cell). The following code (for i=1:length(B)), read and write certain the "nc" files from the home directory based on the cast number defined in "B".
for j = 1 : length(B{i}(:))
data{j}=sprintf('%s%s_0%sO.nc', directory,'obs',B{i}{j});
end
I tried to put the above code in the other loop. It should to read the separate path and file name from the each cell defined based on the numbers of the cast in "B", and write in a new cell in the same cell size of "B".
I tried for the different loops, unfortunately doesn't work.
e.g.,
C2=1;
for i = 1 : length(B)
for j = 1 : length(B{i}(:))
Data1{C2}=sprintf('%s%s_0%sO.nc', directory,'obs',B{i}{j});
C2=C2+1;
end
Data2{i}=Data1;
end
Or
count=0;
for i = 1 : length(B)
count=count+1;
for j = 1 : length(b{i}(:))
data{j}=sprintf('%s%s_0%sO.nc', directory,'obs',B{i}{j});
end
Data{count}=data;
end
Thanks, if anybody can help me. Cheers,

Answers (0)

Categories

Find more on C Shared Library Integration in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!