what i'am doing wrong?

mean1=[10;70;90;20];
class1='ST';
class2='AK';
class3='SN';
for j=1:size(mean1,1)
if (0<mean1(j))&(mean1(j)>=60)
class=class1
end
if(61<=mean1(j))&(mean1(j)>=80)
class=class2
end
if(81<=mean1(j))&(mean1(j)>=100)
class=class3
end
end
it show answer :
ST
ST
AK
it should show:
ST
AK
SN
ST
What i'm doing wrong?can someone show me how to do it right?
Thanks, Amir

 Respuesta aceptada

Walter Roberson
Walter Roberson el 11 de Abr. de 2011

0 votos

if (0<mean1(j))&(mean1(j)<=60)
and so on.

3 comentarios

Amir Hamzah UTeM
Amir Hamzah UTeM el 11 de Abr. de 2011
omg..silly me...
by the way,how can i store the result in cell array?
i want to store it something like this in workspace:
C=[ST
AK
SN
ST]
Andrei Bobrov
Andrei Bobrov el 11 de Abr. de 2011
mean1=[10;70;90;20];
class1='ST';
class2='AK';
class3='SN';
out = [];
for j=1:size(mean1,1)
if (0<mean1(j))&(mean1(j)<60), class=class1;
elseif(61<=mean1(j))&(mean1(j)<80), class=class2;
else class=class3;
end
out = [out;{class}]
end
Amir Hamzah UTeM
Amir Hamzah UTeM el 11 de Abr. de 2011
thanks abobroff

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda 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