Effacer les filtres
Effacer les filtres

Get Column Name if matrix row value is 1

1 vue (au cours des 30 derniers jours)
joms
joms le 3 Juin 2019
Commenté : joms le 5 Juin 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 commentaires
joms
joms le 4 Juin 2019
Modifié(e) : joms le 4 Juin 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 le 4 Juin 2019
Modifié(e) : joms le 4 Juin 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 '}

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 4 Juin 2019
Modifié(e) : Stephen23 le 4 Juin 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 commentaire
joms
joms le 5 Juin 2019
Thank you very much this works exactly the way i want

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2013b

Community Treasure Hunt

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

Start Hunting!

Translated by