Sorting Column Variable to a Row
古いコメントを表示
I have been given my data in 3 Columns of a table as depicted in the below screenshot (I have had to try and replicate a similar scenario using excel as I can't share the actual data):

and I wish to have it in this format for easier analysis/plots such as surface plots, with NaN is cells where there is no value for that date and category:

Any help would be appreciated.
Thanks,
Huw
採用された回答
その他の回答 (1 件)
SALAH ALRABEEI
2021 年 6 月 16 日
編集済み: SALAH ALRABEEI
2021 年 6 月 16 日
Assume your table ( without labels) is of size nx3; where the 1st col is your dates (in numbers), 2nd is your cat, and the 3rd is the values. See this example
x=[ 1 1 1 2 2 2 2 3 3];
y=[0:8];
z=round(100*rand(1,9));
D = [x;y;z]';
a=unique(D(:,1));
B=nan*ones(length(a),size(D,1));
for i = 1:length(a)
B(i,a(i)==D(:,1))=D(a(i)==D(:,1),3);
end
カテゴリ
ヘルプ センター および File Exchange で Tables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!