Element-wise Conditional Statements in Script

5 ビュー (過去 30 日間)
Zachary Wallick
Zachary Wallick 2019 年 11 月 29 日
コメント済み: Zachary Wallick 2019 年 11 月 30 日
I currently have a script which initiates a "for" loop early on, creating a vector array 3x50.
Later on, I attempt to generate a new 3x50 vector using conditional statements so that when the value is above a certain critical value, then the element returned corresponds to the i,j of a one vector, and if it's below, it returns the i,j of a different vector.
for j=1:3
Qr(j)
for i=1:50
if Pc(i,j)>=P0(i,j)
P12(i,j)=Pc(i,j)
else P12(i,j)=P0(i,j)
end
end
Could someone please explain a way to accomplish this?
Thanks.

採用された回答

Steven Lord
Steven Lord 2019 年 11 月 29 日
Use the max function with two inputs.
  1 件のコメント
Zachary Wallick
Zachary Wallick 2019 年 11 月 30 日
Briliant. Thanks.

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

その他の回答 (1 件)

Geoff Hayes
Geoff Hayes 2019 年 11 月 29 日
Zachary - you seem to be missing an end in your code. Perhaps try
for j=1:3
Qr(j)
for i=1:50
if Pc(i,j)>=P0(i,j)
P12(i,j)=Pc(i,j)
else
P12(i,j)=P0(i,j)
end
end
end

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by