필터 지우기
필터 지우기

Tying to make an array of labels for a certain length

조회 수: 3 (최근 30일)
Killian Flynn
Killian Flynn 2022년 10월 12일
답변: dpb 2022년 10월 12일
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.

답변 (1개)

dpb
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).

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by