フィルターのクリア

creating a new column in a matrix using 'if condition"

2 ビュー (過去 30 日間)
Milan Kumar
Milan Kumar 2019 年 4 月 26 日
編集済み: Stephen23 2019 年 4 月 27 日
On the following matrix:
Untitled.png
I am using the following code which is not giving the right response.
if Reg1(:,3)==0
Reg1(:,10)=0;
else
Reg1(:,10)=a1-b1*Reg1(:,3)+Reg1(:,6);
end
Cannot figure out the issue.
The output is
Untitled.png
  1 件のコメント
Catalytic
Catalytic 2019 年 4 月 26 日
We have no way of knowing what you consider to be the "right response"....

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

採用された回答

Stephen23
Stephen23 2019 年 4 月 27 日
編集済み: Stephen23 2019 年 4 月 27 日
IF will not help you in this situation.
You need to use indexing, e.g.:
Reg1(:,10) = a1-b1*Reg1(:,3) + Reg1(:,6);
idx = Reg1(:,3)==0;
Reg1(idx,10) = 0
  1 件のコメント
Milan Kumar
Milan Kumar 2019 年 4 月 27 日
Thank you. Works for me.

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

その他の回答 (1 件)

Matt J
Matt J 2019 年 4 月 26 日
編集済み: Matt J 2019 年 4 月 26 日
if all( Reg1(:,3)==0 )
Reg1(:,10)=0;
else
Reg1(:,10)=a1-b1*Reg1(:,3)+Reg1(:,6);
end

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by