Operands to the || and && operators must be convertible to logical scalar values.
Show older comments
%%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 Comments
Alina Bhim
on 13 Apr 2018
I'm having a similar error,but i made the change of && to & and i'm still getting that same error and i don't know what to do now.
Walter Roberson
on 13 Apr 2018
Please post your code and the size() of each variable mentioned on the line.
Serkan Saltürk
on 5 Feb 2021
Some of data can be array. Be carefull about that.
Carlos David Albarracin
on 22 Jul 2023
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
on 22 Jul 2023
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.
Accepted Answer
More Answers (4)
Evan Ekblaw
on 11 Sep 2020
Edited: Walter Roberson
on 24 Feb 2022
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 Comment
Steven Lord
on 11 Sep 2020
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
on 2 Jun 2019
0 votes
Operands to the || and && operators must be convertible to logical scalar values.
Error in vol_down (line 8)
if((dwn==0)||(dwn==1))
1 Comment
Walter Roberson
on 2 Jun 2019
Your dwn variable is not a scalar.
Patrick Benz
on 17 Mar 2021
Edited: Patrick Benz
on 17 Mar 2021
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 Comments
Walter Roberson
on 17 Mar 2021
Tiefe<(mu_Tiefe-4*sigma_Tiefe)|| Tiefe>(mu_Tiefe+4*sigma_Tiefe)
in MATLAB, the || operator is the "short-circuit or" operator, and can only be used if the two sides compute scalars. "short-circuit or" means that the first expression, which must be scalar, is computed, and if it is found to be (scalar) non-zero value, that the second expression is literally not computed.
The | operator on the other hand, is element-wise logical or, and when two arrays of comptible size are present, it computes each element on the left "or" the element on the right, doing array expansion if needed. The result is a logical array of size implied by any necessary expansions.
Notice that you are checking to see if a value is less than a value, or more than a different value. The result would be false if the value is inside the two boundaries, such as -5 < -3 | -5 > 1 is true, and 7 < -3 | 7 > 1 is true, but 0 < -3 | 0 > 1 is false. So the code is equivalent to
~(mu_Tiefe-4*sigma_Tiefe <= Tiefe & Tiefe <= mu_Tiefe-4*sigma_Tiefe)
It is valid to test to see if a value is outside a particular range, but humans usually find it easier to read and understand a test to check to see whether a value is inside a particular range
The test could also be written
abs(Tiefe - mu_Tiefe) > 4*sigma_Tiefe
Patrick Benz
on 17 Mar 2021
Notice that you are checking to see if a value is less than a value, or more than a different value
Yes, I know.
while Tiefe<(mu_Tiefe-4*sigma_Tiefe)| Tiefe>(mu_Tiefe+4*sigma_Tiefe)
Tiefe(:,1)=normrnd(mu_Tiefe, sigma_Tiefe,Anzahl,1);
end
With this while loop I want to make sure that every value of the Array "Tiefe" is inside the boundaries of mu_Tiefe+-4*sigma_Tiefe.
But your approchment seems smarter. Thx
Walter Roberson
on 17 Mar 2021
Have you considered just truncating the distribution? Then you would not have to loop.
You are doing a vector test, and vector tests succeed only if all of the elements are non-zero. So your test would fail (the while would terminate) if there was even one entry that was within range. Which is not what you want. You want to make sure that they are all in range, and if any are not in range, you want to replace only those ones. Using your logic, it would look like
mask = Tiefe<(mu_Tiefe-4*sigma_Tiefe)| Tiefe>(mu_Tiefe+4*sigma_Tiefe);
while any(mask)
Tiefe(mask) = normrnd(mu_Tiefe, sigma_Tiefe, nnz(mask), 1);
mask = Tiefe<(mu_Tiefe-4*sigma_Tiefe)| Tiefe>(mu_Tiefe+4*sigma_Tiefe);
end
Patrick Benz
on 17 Mar 2021
I don't see how truncating the distribution should help me. The values I am using are normal distributed with a certain mü and sigma. But due to other conditions I only want to use the area of 4 sigma (roughly 96% of the values of the distribution) for this.
How can I test if all the values of the array are inside the range?
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)
Tiefe_1(mask1)
nnz(mask2)
Tiefe_2(mask2)
plot(1:100, Tiefe_1(1:100), 'k', 1:100, Tiefe_2(1:100), 'b');
Patrick Benz
on 24 Mar 2021
I will try this way, thx
lakshmi Shree B
on 24 Feb 2022
0 votes
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 Comments
per isakson
on 24 Feb 2022
Edited: per isakson
on 24 Feb 2022
What are the values of file and path?
Walter Roberson
on 24 Feb 2022
Your code is trying to test whether the user canceled on a call to uigetfile or uiputfile
Although it is true that file and path will both be returned as 0 if that happens, consider the case where the user does not cancel. In such a case, you would be comparing a vector of characters to binary 0 on the left side of the && getting a logical vector on the left. But unless the user just happened to select a file with a one-character name (including extension), that would be an error on the left because && cannot operate on vectors. And on the right hand side, the path is certainly going to be more than one character if the user did not cancel, and so the == is going to be a vector and so would fail the && requirements.
There is no situation in which you can get a numeric 0 for the path in which you did not also get a numeric 0 for the file name, so there is no need to test both variables so you do not need the && part.
What I recommend as the test for cancel is
if isnumeric(file)
This can only be true if the user canceled, and will be a scalar.
This test is also compatable with the possibility that you coded a uigetfile() with 'MultiSelect', 'on' -- a case in which the file output would be a cell array of character vectors if the user selected more than one file, but would be a character vector if the user selected only one file, and would be numeric 0 if the user canceled.
To handle multiselect, I suggest
if isnumeric(file)
%case where user canceled
end
file = cellstr(file);
If the user selected only one file, then the cellstr() will wrap the character vector with {} turning it into a cell array of character vector. But if the user selected more than one file so that file is already a cell array of character vectors, then cellstr() will leave it unmodified. Thus either way after the cellstr() call, file will be a cell array of character vectors. This logic avoids having to treat the single-file case differently than the multi-file case.
lakshmi Shree B
on 25 Feb 2022
Ill try this out .. Thank you..
lakshmi Shree B
on 25 Feb 2022
[file,path ] = uigetfile('*.dat');
Its a video input (mp4 converted to dat file)
Walter Roberson
on 25 Feb 2022
[file, filedir] = uigetfile('*.dat');
if isnumeric(file)
return; %user cancel
end
filename = fullfile(filedir, file);
Categories
Find more on MATLAB 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!