Readonly: Operands to the || and && operators must be convertable to logical scalar values. is eqal3, 153

Asked by Hafeezullah Amin

Hafeezullah Amin (view profile)

on 20 Jun 2019
Latest activity Commented on by Aravind Ravikumar

Aravind Ravikumar (view profile)

on 20 Jun 2019 Hi, Can any one have idea, how to resolve it. This is freqently appearing when I run my code.

Release

R2019a

Answer by Aravind Ravikumar

Aravind Ravikumar (view profile)

on 20 Jun 2019

You get this when one or both operands are arrays. E.g.,
>> [1 2 3] && [4 5 6]
Operands to the || and && operators must be convertible to logical scalar values.
Check the two expressions or variables you are using for the || or && operation. You are using them as scalars but they are not.
You could refer to this link too.

Hafeezullah Amin

Hafeezullah Amin (view profile)

on 20 Jun 2019
This is my code: I have loaded a file name S(1).mat, which contained many matices of different sizes. I want to extract matrix of size (129x10000 or above). I have loaded EEGLAB, from where I am using their function pop_importdata(). I have attached the print screen of my workspace which the loaded data. ********************************************************
clc;
for S =1:100
load(['C:\Users\....\S (' int2str(S) ').mat']);% data
z_c = whos;
sam = 0;
for k = 1:length(z_c)
if z_c(k,1).size(1,1) == 129 && z_c(k,1).size(1,2)>10000
name = z_c(k,1).name;
end
if z_c(k,1).size(1,1) == 129 && z_c(k,1).size(1,2)<10000 && z_c(k,1).size(1,2)>1
name1(k,:) = z_c(k,1).name;
sam = [sam + length(eval(name1(k,:)))];
end
end
epo = str2num(name(length(name)));
addpath (genpath('C:\Users\...\MATLAB\eeglabdevelopers')) % EEG lab folder
EEG = pop_importdata('data',name,'dataformat','matlab','srate',250);
eeg = [EEG.data(1:129,:)];
% new folder for cleaned file
name1 = (['C:\Users\...\EEG\S (' int2str(S) ').mat']);
save(name1,'eeg')
clear all;
end
*********************************************************************
Aravind Ravikumar

Aravind Ravikumar (view profile)

on 20 Jun 2019
The only way I can imagine the error being genereted is cause of z_c(k,1).size(1,x) not being a scalar. Could you maybe try logging that before the if statements? Also, could you try using z_c(k).size(x) instead?