Converting table within Cell arrays to matric in Matlab

조회 수: 4 (최근 30일)
Muhammad Usman Saleem
Muhammad Usman Saleem 2022년 2월 6일
댓글: Muhammad Usman Saleem 2022년 2월 8일
I'm proccessing daily temperature data since 1991 to 2022. I've proccess them into over 36 different area of interests and convert them into cell array of size 30*36 (past 30 years daily data over 36 locations). See below the screen shot of my output variable which contains this data:
When I clicked on the cell output{1,1} , it's showed me a table having two columns i.e., Date and Soilw (Date column contains date corresponding to temperature --soilw). See the image below:
I want to get all temperature data on 36 locations since past 30 years so, I want a cell array of size (1*36). In this cellarray{1,1} will contains a table having two columns first will be dates since 1991-2022 and second column as Soilw (Temperature). Please see below
Note: The above image just showing one year data (356 days) into 36 locations how can I make 30 years data in this cell array over 36 locations?
Many thanks for solution of this problem?

채택된 답변

Voss
Voss 2022년 2월 6일
You don't state how, in each cell of your wantedcell, you want to combine 30 tables with 365 rows each into one table with 365 rows, but I'll assume it's by averaging each day's data over the 30 years for that given location:
% some variables the same size and type as yours:
t = table((1:365).',randn(365,1));
c = repmat({t},30,36);
% to average all years' data by day for each location:
[m,n] = size(c);
new_c = cell(1,n);
for ii = 1:n
data = zeros(365,1);
for jj = 1:m
data = data+c{jj,ii}{:,2};
end
data = data/m;
new_c{ii} = table((1:365).',data);
end
new_c
I've used 1:365 for the days of the year. You may use datetime() variables instead.
  댓글 수: 3
Voss
Voss 2022년 2월 8일
Something like this should work:
% some variables the same size and type as yours:
t = table((1:365).',randn(365,1));
c = repmat({t},30,36);
n = size(c,2);
new_c = cell(1,n);
for ii = 1:n
new_c{ii} = vertcat(c{:,ii});
end
class(new_c{1})
ans = 'table'
size(new_c{1})
ans = 1×2
10950 2
Muhammad Usman Saleem
Muhammad Usman Saleem 2022년 2월 8일
Thank you @__ , you are hidden scientist, you're rising star with one of most simple name "_" Thank you so much for this solution. I request you please, make this solution as seperate solution to this thread so that I able to accept your kind question ?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by