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

1 次查看(过去 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?

回答(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