Azzera filtri
Azzera filtri

Tying to make an array of labels for a certain length

3 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

dpb
dpb il 12 Ott 2022
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).

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by