Operands to the || and && operators must be convertible to logical scalar values.
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
dpb
on 6 Jun 2019
Edited: dpb
on 7 Jun 2019
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 Comments
dpb
on 7 Jun 2019
You also did not address the other question regarding what is LPi and what are you trying to compute overall?
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!