make result matrix for comparing of (for example) 20 inputs matrix with 20 refrences matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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?
0 comentarios
Respuesta aceptada
Chaowei Chen
el 3 de Sept. de 2011
You can use cell matrix, which contains mixed type of values. In your case, the first column and row are string while the rest is logical values.
Result = cell(21,21);
Result{2,1}='the first name of the 20 ref matrices';
Result{3,1}='the second name of the 20 ref matrices';
Result{1,2}='the first name of the 20 input matrices';
and so on. You can arrange a for loop doing this. If you can tell me the template of the names. I am happy to assist you.
Result{2,2}=true; % false
gives the comparison result of the first pair.
5 comentarios
Chaowei Chen
el 4 de Sept. de 2011
clc;clear
ref_list=dir([uigetdir '\*.xls']);
inp_list=dir([uigetdir '\*.xls']);
Result=cell(numel(ref_list)+1,numel(inp_list)+1);
Result(1,2:end)={ref_list(:).name};
Result(2:end,1)={inp_list(:).name};
for i=1:numel(inp_list)
for r=1:numel(ref_list)
Result{i+1,r+1}=strcmp(ref_list(r).name,inp_list(i).name);
end
end
Result
Chaowei Chen
el 4 de Sept. de 2011
hi Mohammad,
You can modify above code to fit in your application. Mostly, you need to load your xls file and do the loaded matrix for comparison
Más respuestas (2)
Walter Roberson
el 3 de Sept. de 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!
Andrei Bobrov
el 3 de Sept. de 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),[]);
0 comentarios
Ver también
Categorías
Más información sobre Other Formats 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!