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

조회 수: 915 (최근 30일)
%%Spectrometer or Ionisation
if ~iscell(folders) && isnan(folders) && strcmpi(Type,'Io')
folders={'i1'};
elseif ~iscell(folders) && isnan(folders) && strcmpi(Type,'Sp1')
folders={'s1'};
is the code how to solve the error
Operands to the and && operators must be convertible to logical scalar values.Error in SearchMCfiles_mp (line 33) if ~iscell(folders) && isnan(folders) && strcmpi(Type,'Io')
  댓글 수: 5
Carlos David Albarracin
Carlos David Albarracin 2023년 7월 22일
Warning: Error occurred while executing the listener callback for event MLFB defined for class
slmle.internal.slmlemgr:
Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or
ALL functions to reduce operands to logical scalar values.
Error in slmle.internal.MLFBEditor/callback
Error in slmle.internal.MLFBEditor/init>@(varargin)obj.callback(varargin{:})
Error in slmle.internal.slmlemgr/action
Error in slmle.internal.slmlemgr/init>@(varargin)obj.action(varargin{:})
Error in message.internal.executeCallback
Warning: Error occurred while executing the listener callback for event MLFB defined for class
slmle.internal.slmlemgr:
Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or
ALL functions to reduce operands to logical scalar values.
Error in slmle.internal.MLFBEditor/callback
Error in slmle.internal.MLFBEditor/init>@(varargin)obj.callback(varargin{:})
Error in slmle.internal.slmlemgr/action
Error in slmle.internal.slmlemgr/init>@(varargin)obj.action(varargin{:})
Error in message.internal.executeCallback
Warning: Error occurred while executing the listener callback for event MLFB defined for class
slmle.internal.slmlemgr:
Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY
or ALL functions to reduce operands to logical scalar values.
Error in slmle.internal.MLFBEditor/callback
Error in slmle.internal.MLFBEditor/init>@(varargin)obj.callback(varargin{:})
Error in slmle.internal.slmlemgr/action
Error in slmle.internal.slmlemgr/init>@(varargin)obj.action(varargin{:})
Error in message.internal.executeCallback
> In slmle.internal.slmlemgr/action
In slmle.internal.slmlemgr/init>@(varargin)obj.action(varargin{:})
In message.internal.executeCallback
In slmle.internal.MLFBEditor/createToolStripContext
In slmle.internal.MLFBEditor/open
In slmle.internal.slmlemgr/open
In slmle.internal.EMLEditorApi/documentOpen
In open_editor (line 72)
In eml_man (line 56)
In eml_function_man>create_ui (line 169)
In eml_function_man (line 26)
In eml_chart_man>create_ui (line 104)
In eml_chart_man (line 20)
In dispatch_task (line 12)
In eml_man (line 66)
In studio_redirect>try_specialized_editor_open (line 761)
In studio_redirect>open_object (line 775)
In studio_redirect (line 33)
In sfprivate (line 15)
In slsf>blk_open_method (line 784)
In slsf (line 55)
Walter Roberson
Walter Roberson 2023년 7월 22일
That appears to have to do with Standard Linear Mixed Effect model . I see a hint that maybe some LME code was compiled, but it is difficult to be sure.
My guess is that something came out empty that the code does not expect to be empty. It is difficult to get any hints about exactly what might be happening.
You will probably need to open a support case.

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

채택된 답변

Patrik Ek
Patrik Ek 2014년 7월 28일
There is 2 types of logical operators for some operations in matlab. For and can you use either && or & to operator on scalars. However to logically compare vectors (which is done per element), you must use &. If you want to see if two vectors are equal, use the function isequal(a,b) instead. The same applies for | |.
  댓글 수: 3
Chris Smith
Chris Smith 2019년 11월 30일
This is perfect. But I must ask, why must you use & when comparing vectors?
Walter Roberson
Walter Roberson 2019년 11월 30일
&& is the "short circuit" and operation, that does not evaluate the right hand side if the left hand side is false. But when you are working with vectors, true or false of the left hand side is element-by-element, and it isn't really possible to only evaluate the right hand side with respect to selected elements. So && and || are simply not permitted except on scalars, by definition.
Note: if you are using && or || chances are strong that you should be considering using any() or all() . Sometimes it make sense to use all(condition1)&&all(condition2)

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

추가 답변 (4개)

Evan Ekblaw
Evan Ekblaw 2020년 9월 11일
편집: Walter Roberson 2022년 2월 24일
while xf>=360 && xf<=390
tries=tries+1;
[v0,theta]=swing_choices();
angle=theta*34*(pi/180);
v0=v0*(cos(angle));
xf=x0+v0*t+.5*a_x*t.^2;
plot(xf,y,"--k")
end
Dont see the error here.
  댓글 수: 1
Steven Lord
Steven Lord 2020년 9월 11일
What is the size of xf when that first line executes and throws that error?
[true false] && [true true] % Will throw this same error
[true false] & [true true] % Will return a 1-by-2 logical array
You likely want to use & and wrap that condition in any or all.

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


Megha S
Megha S 2019년 6월 2일
Operands to the || and && operators must be convertible to logical scalar values.
Error in vol_down (line 8)
if((dwn==0)||(dwn==1))

Patrick Benz
Patrick Benz 2021년 3월 17일
편집: Patrick Benz 2021년 3월 17일
I get the same error.
Tiefe<(mu_Tiefe-4*sigma_Tiefe)|| Tiefe>(mu_Tiefe+4*sigma_Tiefe)
Tiefe is an 696x1 array.
When I'm only copying the left or the right part into the command Window, I get logical arrays with 696x1.
When I change to code to:
Tiefe<(mu_Tiefe-4*sigma_Tiefe)| Tiefe>(mu_Tiefe+4*sigma_Tiefe)
it works. But do I have a logical error in my code?
I want to check if every value in the array "Tiefe" is matching one of the two conditions.
Or is there a better option to compare arrays with scalar values?
  댓글 수: 6
Walter Roberson
Walter Roberson 2021년 3월 17일
If you truncate the distribution then it will not be able to generate values outside the range, so there would be no need to test.
mu_Tiefe = 2;
sigma_Tiefe = .2;
pd = makedist('Normal', mu_Tiefe, sigma_Tiefe);
td = truncate(pd, mu_Tiefe-4*sigma_Tiefe, mu_Tiefe+4*sigma_Tiefe);
rng(655321);
Tiefe_1 = random(pd, 1, 100000);
rng(655321);
Tiefe_2 = random(td, 1, 100000);
mask1 = Tiefe_1<(mu_Tiefe-4*sigma_Tiefe)| Tiefe_1>(mu_Tiefe+4*sigma_Tiefe);
mask2 = Tiefe_2<(mu_Tiefe-4*sigma_Tiefe)| Tiefe_2>(mu_Tiefe+4*sigma_Tiefe);
nnz(mask1)
ans = 4
Tiefe_1(mask1)
ans = 1×4
1.1288 2.8282 2.8564 1.1942
nnz(mask2)
ans = 0
Tiefe_2(mask2)
ans = 1×0 empty double row vector
plot(1:100, Tiefe_1(1:100), 'k', 1:100, Tiefe_2(1:100), 'b');

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


lakshmi Shree B
lakshmi Shree B 2022년 2월 24일
Operands to the logical and (&&) and or (||) operators must be convertible to logical scalar values.
Error in test_ppg (line 9)
if (file == 0) && (path == 0)
  댓글 수: 5
lakshmi Shree B
lakshmi Shree B 2022년 2월 25일
[file,path ] = uigetfile('*.dat');
Its a video input (mp4 converted to dat file)
Walter Roberson
Walter Roberson 2022년 2월 25일
[file, filedir] = uigetfile('*.dat');
if isnumeric(file)
return; %user cancel
end
filename = fullfile(filedir, file);

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

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by