Clear Filters
Clear Filters

I want to extract cell array

1 view (last 30 days)
Habtamu Tsegaye
Habtamu Tsegaye on 13 Apr 2022
Answered: Habtamu Tsegaye on 13 Apr 2022
I do have 1x7 cell arraiy which contain 5488x4. 1st col is year, 2nd col is month, 3rd isday and 4th is the dily rainfall. I want to extract the daily data from each cell and make other cell aray contain 7 daily rainfall elements. How can I do the code? here is my data
it is my trial
for i=1:length(unistsrfr1)
for j = 1:5844
dy_strfr1= rfdata_tsstrfr1{1,i}(1:j,4);
yy= rfdata_tsstrfr1{1,1}(1:j,1);
mm= rfdata_tsstrfr1{1,1}(1:j,2);
dd= rfdata_tsstrfr1{1,1}(1:j,3);
datenum(yy,mm,dd,0,0,0)
end
end

Answers (2)

Walter Roberson
Walter Roberson on 13 Apr 2022
rf_cell = cellfun(@(C) [datenum(C(:,1), C(:,2), C(:,3)), C(:,4)], unistsrfr1, 'uniform', 0);
The result, rf_cell, will be a 1 x 7 cell array, each entry of which is a 5488 x 2 double, with the first column containing the datenum and the second column containing the rainfall.
Note: these days we recommend that you use datetime() objects instead of datenum()

Habtamu Tsegaye
Habtamu Tsegaye on 13 Apr 2022
The result, rf_cell, will be a 1 x 7 cell array, each entry of which is a 5488 x 2 double. I do not need 5488X2double. what I need is 1X7 or 7X1 rainfall elements taken (one by one) from each 1X7cell array in the data attached.

Categories

Find more on Dates and Time in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!