How can I extract matrices from rows of other matrices.

Hello everyone,
I am working on a project for MCDM. I am using AHP method. I need help to apply an algorithm.
I have 4 matrices of 199X4 doubles. i.e.
row1 = [C11 C12 C13 C14];
row2 = [C21 C22 C23 C24];
row3 = [C31 C32 C33 C34];
row4 = [C41 C42 C43 C44];
where C11.....C44 are 199X1 doubles each.
Now, I have to make pairwise comparision matrix from rows of each given matrices. like
CompMat = [row1(1,:); row2(1,:); row3(1,:); row4(1,:)];
Next, I have to apply a function(Which I have already made) to calculate Consistancy. i.e.
CR = ConsistencyAHP( CompMat );
Now, task is to write a script using loops which can give me CR vector for every matrices formed from first row to 199th row.
Thanks in advance.

 Accepted Answer

Using a for-loop will be easiest
row1 = [C11 C12 C13 C14];
row2 = [C21 C22 C23 C24];
row3 = [C31 C32 C33 C34];
row4 = [C41 C42 C43 C44];
CR = zeros(size(row1,1),1); % does ConsistencyAHP return a scalar??
for i=1:size(row1,1)
CompMat = [row1(i,:); row2(i,:); row3(i,:); row4(i,:)];
CR(i) = ConsistencyAHP(CompMat);
end

5 Comments

Hii Ameer,
Thank you very much for your efforts.
Yes, ConsistancyAHP returns scalar.
Also, I want to inform you that in the line
CompMat = [row1 (i, :); row2 (i, :); row3 (i, :); row4 (i, :)];
I am getting error as
Error: File: analysis.m Line: 304 Column: 23
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
Please suggest me whts went wrong.
Remove the space between row1 and (i, :); Write it exactly like this
CompMat = [row1(i, :); row2(i, :); row3(i, :); row4(i, :)];
%^ No spaces here and after row2, row3 and row4
Dear Ameer,
Thanks it worked.
There was some syntex errors I figured it out. It is great help.
Thank you very much
row1 = [C11 C12 C13 C14];
row2 = [C21 C22 C23 C24];
row3 = [C31 C32 C33 C34];
row4 = [C41 C42 C43 C44];
CR = zeros (size (row1,1), 1); % Yes, ConsistencyAHP return a scalar ??
for i = 1: size (row1,1)
CompMat = [row1(i, :); row2(i, :); row3(i, :); row4(i, :)];
CR (i) = ConsistencyAHP (CompMat);
end

Sign in to comment.

More Answers (0)

Categories

Find more on Linear Algebra in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!