Tying to make an array of labels for a certain length
1 回表示 (過去 30 日間)
古いコメントを表示
Hello. I am trying to make an array which looks like
1 1 1 . .... .
0 0 0 . .. . .
0 0 0 . . .. . .
with a length of m to be stored in bad_labels. I have tried to do this below but I get an error.
cvs_data =readmatrix('spruce tree timber quality.csv');
quality=cvs_data(:,12)
bad_data=cvs_data(quality<=4,1:11)
good_data=cvs_data(quality>=5&quality<=6,1:11);
excellent_data=cvs_data(quality>=7,1:11);
m=min([size(bad_data,1),size(good_data,1),size(excellent_data,1)]);
newdata = [bad_data(1:m,:);good_data(1:m,:);excellent_data(1:m,:)]'
bad_labels(1:3,1:m) = [1; 0 ; 0]
Any help will be greatly appreciated.
0 件のコメント
回答 (1 件)
dpb
2022 年 10 月 12 日
Why the min() operation? You'll need the same length of the quality indicator as the height of the data.
I'd suggest approaching is somewhat differently; instead of a Nx3 array; save the quality index as a categorical variable --
edges=[-inf 5 7 inf];
categorical(discretize(q,edges),[1:3],{'bad';'good';'excellent'},"Ordinal",1);
Then you can do things like
cvs_data(quality=='good',:) % only good
cvs_data(quality>'bad',:) % better than bad --> good; excellent
and, if you would heed previous advice and put into a table instead of a zillion different variables, it would very easy to do analyses with quality as a grouping variable (or with other variables as well).
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Tables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!