MATLAB Answers

Info

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

index in matrix using loop

1 ビュー (過去 30 日間)
mohamed gamal
mohamed gamal 2019 年 4 月 28 日
終了済み: MATLAB Answer Bot 2021 年 8 月 20 日
hi i have an matrix in my code that i want to do some calculation on each index in it so first of all i want to check if that index is greater then 0 then i multiply by area then store it in new varible calld fill
if not i multiple this index with area then store it in variable calld fill
how can i do it
  3 件のコメント
mohamed gamal
mohamed gamal 2019 年 4 月 30 日
0.500000000000000 0.500000000000000
0.250000000000000 0.500000000000000
-0.500000000000000 -0.500000000000000
like this one and i want to do if the number in the index is + then multiple *AREA+fill
if its - then cut= the numer in matrix*Area +cut

回答 (1 件)

Kevin Phung
Kevin Phung 2019 年 4 月 30 日
m = [0.5 0.5; 0.25 0.5; -0.5 -0.5] % your sample matrix
f = m(m>0) * A + fill
c = m(m<0) *A + cut
^ this only return the values that meet the positive/neg criteria. If you want to keep the same dimensions then do this:
new_m = m; %copy
new_m(m>0) = m(m>0) * A + fill; %operate on positives
new_m(m<0) = m(m<0) * A - cut;

Community Treasure Hunt

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

Start Hunting!

Translated by