Tying to make an array of labels for a certain length

2 visualizaciones (últimos 30 días)
Killian Flynn
Killian Flynn el 12 de Oct. de 2022
Respondida: dpb el 12 de Oct. de 2022
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.

Respuestas (1)

dpb
dpb el 12 de Oct. de 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).

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by