How can i create a char of a character vector as a result of this routine?

1 visualización (últimos 30 días)
%The character output vector should look like as k1out={'V1'; 'V5'; 'V3'; 'V2'; 'V1'}
%The code is giving me an error= Index exceeds matrix dimensions in this
%output k1out=char(k1(j))
%I have tried different posibilities but still i cant get the character
%vector that i'm showing in the first line
%Thanks for your help
Stotal=[0.38 0.007 0.09 0.18 0.34;0.18 0.19 0.17 0.03 0.46;0.19 0.0162 0.68 0.09 0.02;0.08 0.45 0.11 0.045 0.30;0.39 0.09 0.34 0.13 0.05];
n=5;
k1out=zeros(n,1);
k1=zeros(n,1);
for j=1:n
p(j,1)=max(Stotal(j,:))
k(j,:)=Stotal(j,:)>=p(j)
[row,col]=find(k(j,:)==1)
if col==1
k1={'V1'}
end
if col==2
k1={'V2'}
end
if col==3
k1={'V3'}
end
if col==4
k1={'V4'}
end
if col==5
k1={'V5'}
end
k1out=char(k1(j))
end

Respuesta aceptada

David Hill
David Hill el 29 de Mayo de 2021
Stotal=[0.38 0.007 0.09 0.18 0.34;0.18 0.19 0.17 0.03 0.46;0.19 0.0162 0.68 0.09 0.02;0.08 0.45 0.11 0.045 0.30;0.39 0.09 0.34 0.13 0.05];
lookup={'V1'; 'V2'; 'V3'; 'V4'; 'V5'};
[~,idx]=max(Stotal,[],2);
k=lookup(idx);

Más respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by