フィルターのクリア

Sort and export data from 2 cells

1 回表示 (過去 30 日間)
BN
BN 2020 年 4 月 2 日
コメント済み: Ameer Hamza 2020 年 4 月 2 日
Hey all,
I have 2 cells (A and B). Each one contains three 1x2 tables. In each table, I have a month number column and precipitation amount column. I would like to have a cell or table that presents all January precipitation from each cell arrays of A in one column Below each other, and next column all January precipitation from each cell arrays of B below each other; and do it until December.
the results that I want is something like this: (row are 3 because of 3 cella arrays in each cell and columns are 24 because of 12 for cell A months and 12 for cell B months)
Thank you

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 2 日
Try this
load('A.mat');
load('B.mat');
a = cell2mat(cellfun(@(x) {x{:,2}}, A))';
b = cell2mat(cellfun(@(x) {x{:,2}}, B))';
M = zeros(size(a,1), size(a,2)*2);
M(:,1:2:end) = a;
M(:,2:2:end) = b;
month_names = month(datetime(2020,1:12,1), 'name');
varNames = cell(1,24);
varNames(1:2:end) = strcat(month_names, '_1');
varNames(2:2:end) = strcat(month_names, '_2');
T = table(M);
T = splitvars(T, 1, 'NewVariableNames', varNames);
  2 件のコメント
BN
BN 2020 年 4 月 2 日
Thank you so much
Ameer Hamza
Ameer Hamza 2020 年 4 月 2 日
Glad to be of help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by