make result matrix for comparing of (for example) 20 inputs matrix with 20 refrences matrix
Ältere Kommentare anzeigen
I compared (for example) 20 inputs matrix with 20 references matrix and now i know which matrix is equal which one. but its needed to see final result in a matrix (like Result matrix) 20*20 . in first column must put the name of 20 references matrix with starting from Result(2,1) and in first row must put the name of 20 inputs matrix with starting from Result(1,2). and Result(1,1) must be zero. then each array of this matrix equal to 1 if related reference and input are equal else it must be zero.
my questions:
1-i have the names of references and inputs matrix but how must i put them respective in first column and row.(starting with Result(2,1) and Result(1,2)
2- if one input and one reference matrix is equal, how can i put number 1 in theirs array?
Akzeptierte Antwort
Weitere Antworten (2)
Walter Roberson
am 3 Sep. 2011
You are going to have to use a cell array, as numeric arrays cannot hold strings (names).
RefArrayNames = {'Fred', 'Moon', 'June 2014'};
InputArrayNames = {'Black Sparrow', 'Boatswain', 'MCC-1701-D'};
Result = cell(length(RefArrayNames)+1, length(InputArrayNames)+1);
Result{1,1} = 0;
Result(2:end,1) = RefArrayNames;
Result(1,2:end) = InputArrayNames;
To compare whether two matrices are equal, you can use isequal() . Beware, though, of floating point comparisons!
1 Kommentar
mohammad
am 3 Sep. 2011
Andrei Bobrov
am 3 Sep. 2011
%A - matrix input
%B - matrix references
%AI - names input
%BR - names references
AI = cellstr(char(64+[1:20])');
BR =cellstr(char(64+[1:20]+32)');
A = arrayfun(@(i1)randi(6,2,2),1:4,'un',0)
B = arrayfun(@(i1)randi(6,2,2),1:4,'un',0)
OUT = cell(numel(A)+1);
OUT(2:end,1) = AI';
OUT(1,2:end) = BR';
OUT(2:end,2:end) = reshape(arrayfun(@(i1)isequal(A{idx(i1,2)},B{idx(i1,1)}),1:size(idx,1),'un',0),numel(A),[]);
Kategorien
Mehr zu Cell Arrays finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!