Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Skydriver
Skydriver le 6 Juin 2019
Commenté : Skydriver le 9 Juin 2019
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?

Réponses (1)

dpb
dpb le 6 Juin 2019
Modifié(e) : dpb le 7 Juin 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 commentaires
dpb
dpb le 7 Juin 2019
You also did not address the other question regarding what is LPi and what are you trying to compute overall?
Skydriver
Skydriver le 9 Juin 2019
Thank you finnaly resolved "dpb"

Connectez-vous pour commenter.

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by