Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How can i have a matrix A, that depends of the result of other matrix B, that when there's a x number in B, matrix A changes to 1

2 ビュー (過去 30 日間)
Pedro Vicente
Pedro Vicente 2018 年 10 月 1 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日

So, i have a matrix B(51,10,1000), that have somewhere negative numbers.

And i want a matrix A(51,1000) that when running the matrix B, it gives me a value "1" if it's negative in B. And after there's one "1", all the other lines of A become "2". And if there's is not a negative value the libe of A is "0".

I don't know how to put the part when if there's one 1, all the lines are equal to 2.

something like:

A =[ 0 0 0 0 1 2 2 2 2 ] (this would be a column)
for k= 1:1000
      for i = 1:51
          for j = 1:10
              if B(i,j,k)<=0
                  A(i,k) =1;
                break
              else 
                  A=(i,k) = 0;
              end
          end
      end
  end

回答 (1 件)

Matt J
Matt J 2018 年 10 月 1 日
編集済み: Matt J 2018 年 10 月 1 日
A=cumsum(cumsum(B<0,1),1);
A(A>=2)=2;

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by