フィルターのクリア

how sum all element which are the right of diagonal. where row=colom .....i have done this much but confuse in further operation

1 回表示 (過去 30 日間)
Abdur Rob
Abdur Rob 2020 年 9 月 26 日
コメント済み: Abdur Rob 2020 年 9 月 26 日
function summa = halfsum(A)
%A = randi(n,x,y);
[row,col] = size(A);
if row == col
for r = 1:row
for c = 1:col
summa = sum(A(r,c)) + sum(A(r,c));
end
end
else
fprintf('Input correct matrix.\n')
end
end
  2 件のコメント
Image Analyst
Image Analyst 2020 年 9 月 26 日
Is this homework (sounds a lot like it)? If so, tag as homework. In the meantime, check out triu() and tril(), and consider if r <= or >= c
if c >= r % or....
if c <= r
if you want/need to do it as a for loop.
Abdur Rob
Abdur Rob 2020 年 9 月 26 日
not really ,, actually i'm learning MATLAB and i found this problem from web that's why i need help

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

回答 (1 件)

KSSV
KSSV 2020 年 9 月 26 日
編集済み: KSSV 2020 年 9 月 26 日
Read about triu.
If A is your matrix, use:
iwant = sum(sum(triu(A)))
  3 件のコメント
KSSV
KSSV 2020 年 9 月 26 日
Read the documentation..it is clear in the documentation.
Also you can use loops like below:
A = rand(3) ;
[m,n] = size(A) ;
upper_diagonal = zeros([],1) ;
count = 0 ;
for i = 1:m
for j = 1:n
if i<=j
count = count+1 ;
upper_diagonal(count) = A(i,j) ;
end
end
end

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by