Filter löschen
Filter löschen

make result matrix for comparing of (for example) 20 inputs matrix with 20 refrences matrix

2 Ansichten (letzte 30 Tage)
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

Chaowei Chen
Chaowei Chen am 3 Sep. 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 Kommentare
Chaowei Chen
Chaowei Chen am 4 Sep. 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
Chaowei Chen am 4 Sep. 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Walter Roberson
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
mohammad am 3 Sep. 2011
thanks a lot
the reference names aren't arranged ( i don't have RefArrayNames) and also for inputs. but i think i could arrange by using dir command because references are in a specified folder ( in .xls format) and inputs are in inputs folder. please help how can i use dir for doing this.
but in each time that i compare input and reference the template name of those respectively is 'lable' and 'dfile' . iyhink in this way also could make RefArrayNames and InputArrayNames

Melden Sie sich an, um zu kommentieren.


Andrei Bobrov
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 Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by