matrices, collect, rows, columns

10 ビュー (過去 30 日間)
ali talib
ali talib 2020 年 11 月 10 日
コメント済み: ali talib 2020 年 11 月 10 日
hi every one
I need help with a program to calculate the sum of matrices
If I have a main matrix A and another matrix B and I need to add A+ B = C, then if all of the elements of C are positive, re-combine C+ B and so on, stop when we get a result that is a matrix containing negative elements. finally, we collect all matrices with positive elements.
Regards
  2 件のコメント
James Tursa
James Tursa 2020 年 11 月 10 日
What have you done so far? What specific problems are you having with your code?
How do you want to handle potential infinite looping? How do you want your matrices "collected" at the end of the process? Can you provide a small example?
ali talib
ali talib 2020 年 11 月 10 日
A=[6 5 16; 7 2 5]
B=[1 -1 0;-1 1 0]
A+B=C
if all elements of C are positive, then B+C=D and so on
if one element of C is negative, stop
collect all positive matrices

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

採用された回答

David Hill
David Hill 2020 年 11 月 10 日
C(:,:,1)=A+B;
c=2;
while nnz(C(:,:,end)>0)==numel(C(:,:,end))
C(:,:,c)=C(:,:,c-1)+B;
c=c+1;
end
C=C(:,:,1:end-1);
  1 件のコメント
ali talib
ali talib 2020 年 11 月 10 日
thanx a lot David

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by