hi, I have some troubles with matrices. say there's a n x 7 matrix. if selected row's 6th column of the element is zero, then -action-. and this condition holds for every row.
how can I write a code for this condition using if-else statement?
thank you in advance.

3 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 16 日
This is not clear, give an example
Gary
Gary 2013 年 11 月 16 日
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 16 日
Giving an example we can'g test is not useful, instead of posting an image, post a text

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

 採用された回答

Andrei Bobrov
Andrei Bobrov 2013 年 11 月 16 日
編集済み: Andrei Bobrov 2013 年 11 月 16 日

0 投票

A=[85 80 20 0 100;100 70 50 55 0;50 60 58 0 39;60 100 44 100 0];
a = [1.3 1.3 1.2 0 1.2;1.2 1.2 1.3 1.3 0];
[ii,~] = find(A'==0);
out = sum(A.*a(ii - 3,:),2);
with using if-end
[ii,~] = find(A'==0);
n = size(A,1);
out = zeros(n,1);
for jj = 1:n
if ii(jj) == 4
out(jj) = A(jj,:)*[1.3 1.3 1.2 0 1.2]';
else
out(jj) = A(jj,:)*[1.2 1.2 1.3 1.3 0]';
end
end

1 件のコメント

Gary
Gary 2013 年 11 月 17 日
wow thanks a lot!!!!

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

その他の回答 (0 件)

カテゴリ

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

質問済み:

2013 年 11 月 16 日

コメント済み:

2013 年 11 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by