Operands to the || and && operators must be convertible to logical scalar values.
조회 수: 2 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (1개)
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
2019년 6월 7일
You also did not address the other question regarding what is LPi and what are you trying to compute overall?
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!