Write a program that will take a random 4x4 input matrix and will check whether 3 out of the total 4 numbers in column 4 are greater than the numbers in column 2. If thats true the program displays "C4 greater than C2". If that is false it displays "C4 less than C2"

3 件のコメント

Walter Roberson
Walter Roberson 2011 年 12 月 13 日
http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
Sean de Wolski
Sean de Wolski 2011 年 12 月 13 日
So is it three numbers greater than a number or three numbers greater than a specific number.
[1 2 3 4], [2 2 2 1], the second one has three numbers greater than a value in the first.
Vijay
Vijay 2011 年 12 月 13 日
It is at least three numbers from the fourth column each having a value greater than all the elements of the second column.
I hope I could clarify better.
Thanks

サインインしてコメントする。

回答 (1 件)

Wayne King
Wayne King 2011 年 12 月 13 日

0 投票

x = randn(4,4);
Y = x(:,4)-x(:,2);
if (length(Y(Y>0))>2)
disp('C4 greater than C2');
elseif (length(Y(Y>0))<2)
disp('C4 less than C2');
else
disp('What do you want to say here?');
end
I'm assuming you mean at least 3 of the 4 numbers in column 4 are greater than in column 2. What do you want to say if it is 2 greater and 2 less?

2 件のコメント

Vijay
Vijay 2011 年 12 月 13 日
Yes you are right.
Let's make it a 3x4 matrix then.
I assume that only the last else statememnt will be dropped right?
Thanks
Wayne King
Wayne King 2011 年 12 月 14 日
yes, that's right.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

質問済み:

2011 年 12 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by