Get Column Name if matrix row value is 1

3 次查看(过去 30 天)
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 个评论
joms
joms 2019-6-4
编辑:joms 2019-6-4
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 2019-6-4
编辑:joms 2019-6-4
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 '}

请先登录,再进行评论。

采纳的回答

Stephen23
Stephen23 2019-6-4
编辑:Stephen23 2019-6-4
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'

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

产品


版本

R2013b

Community Treasure Hunt

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

Start Hunting!

Translated by