Get Column Name if matrix row value is 1

2 visualizaciones (últimos 30 días)
joms
joms el 3 de Jun. de 2019
Comentada: joms el 5 de Jun. de 2019
Im creating a labeling for x axis of a graph that track change in value based on first row of a matrix as basevalue.
I had managed to code until validmatrix array but i dont know how to extract table label if valid index is "1".
validindexarray determines what element changes per row and the "parameterlabel" is the label name of the table. If validndex is 1 then desiredresult will get the parameter label from the table.
Thanks for your help.
parameterlabel={ 'A' 'B' 'C' 'D' 'E'}
parametervalue=[ 1 2 4 5 3; 2 2 4 5 3; 1 2 5 5 3; 1 2 3 5 2]
validindex= [0 0 0 0 0; 1 0 0 0 0; 0 0 1 0 0; 0 0 1 0 1]
%%My code until here↑↑↑↑
%Need help beyond this line↓↓↓
desiredresult={'','A 1→2','C 4→5','C 4→3 ,E 3→2 '}
xticklabels(desiredresult)
xticklabels({'','A 1→2','C 4→5','C 4→3 ,E 3→2'})
  4 comentarios
joms
joms el 4 de Jun. de 2019
Editada: joms el 4 de Jun. de 2019
validindexarray determines what element changes per row and the "parameterlabel" is the label name of the column where the value change. If validndex is 1 then desiredresult will get the parameter label from the table. ' 4→3,3→2' are the values that change C , E are columns name where the change occurs
joms
joms el 4 de Jun. de 2019
Editada: joms el 4 de Jun. de 2019
since there are 5 rows C and E will be combined like this
desiredresult={'','A 1→2','C 4→5','C 4→3 ,E 3→2 '}

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23
Stephen23 el 4 de Jun. de 2019
Editada: Stephen23 el 4 de Jun. de 2019
First download Jos's excellent runindex:
Data:
L = {'A','B','C','D','E'};
P = [1 2 4 5 3; 2 2 4 5 3; 1 2 5 5 3; 1 2 3 5 2]
X = [0 0 0 0 0; 1 0 0 0 0; 0 0 1 0 0; 0 0 1 0 1]
Method:
Z = cell2mat(cellfun(@runindex,num2cell(X,1),'uni',0));
[R,C] = find(X);
V = 1:nnz(X);
F = @(r,c)sprintf('%s %d->%d',L{c},P([r-Z(r,c),r],c));
D = arrayfun(F,R,C,'uni',0);
G = @(s)s(3:end);
H = @(d){G(sprintf(', %s',D{d}))};
D = accumarray(R,V(:),[],H);
D(cellfun('isempty',D)) = {''}
Giving:
D =
''
'A 1->2'
'C 4->5'
'C 4->3, E 3->2'
  1 comentario
joms
joms el 5 de Jun. de 2019
Thank you very much this works exactly the way i want

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2013b

Community Treasure Hunt

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

Start Hunting!

Translated by