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

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개)

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

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2019년 4월 26일

편집:

2019년 4월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by