필터 지우기
필터 지우기

Operands to the || and && operators must be convertible to logical scalar values.

조회 수: 1 (최근 30일)
Skydriver
Skydriver 2019년 6월 6일
댓글: Skydriver 2019년 6월 9일
I have a problem with my coding about Operands to the || and && operators must be convertible to logical scalar values.. Here in detail:
for i=1:length(FS);
depth_all7=[]
if FS < 1 && Depth<20;
LPi= (1-FS(i))*(J - K*Depth(i));
elseif FS>= 1 && Depth > 20
LPi= 0;
elseif FS <=1 && Depth>=20
LPi = 0;
elseif FS >=1 && Depth<=20
LPi= 0;
depth_all7=[depth_all7;LPi]
end
fprintf(fid_X,'%2.4f %2.4f %2.4f %2.4f %2.6f %10s\n', Depth(i),CSR(i), CRR(i), FS(i), LPi(i), teks_i);
end
Is there any one can help me?

답변 (1개)

dpb
dpb 2019년 6월 6일
편집: dpb 2019년 6월 7일
Presuming FS and Depth are vectors, then you need to subscript them as, for example
if FS(i) < 1 && Depth(i)<20
in all expressions...otherwise FS<1 or Depth>=20 return logical vectors of size(FS) or size(Depth)
You can do the assignments using logical addressing without the loop...note as you've written the loop that the depth_all7 array will be equivalent to
depth_all7=zeros(sum(FS>=1 & Depth<=20,1));
so numel() will be the number of cases that satisfy the condition, not the same size as Fs. If that is the intent, that's fine.
The first conditional case is peculiar -- if LPi is a single value not a predefined array, then it is overwritten each pass through the loop and otherwise never used. One would guess that isn't the intent.
  댓글 수: 4
dpb
dpb 2019년 6월 7일
You also did not address the other question regarding what is LPi and what are you trying to compute overall?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by