make result matrix for comparing of (for example) 20 inputs matrix with 20 refrences matrix
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Chaowei Chen
2011 年 9 月 3 日
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 件のコメント
Chaowei Chen
2011 年 9 月 4 日
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
2011 年 9 月 4 日
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
その他の回答 (2 件)
Walter Roberson
2011 年 9 月 3 日
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
2011 年 9 月 3 日
%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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!