getting this message "Operands to the || and && operators must be convertible to logical scalar values." trying to allocate a value to a cell.

1 view (last 30 days)
app.HSV =0:15; % app.HSV
app.tcof = 0:400000;
app.invf =0:1;
app.HSV = app.HSEditField.Value;
app.invf = app.InterventionFactorEditField.Value;
app.c1h1 = app.C1HI1EditField_6.Value; % declaring variable for c1h1
if (app.HSV > 0 && app.HSV <= 4 ) && ( app.tcof > 0 && app.tcof <= 39548) && app.invf <= 1 % Declaring conditions for result display
app.C1HI1EditField_6.Value = app.HSV * app.tcof * app.InterventionFactorEditField.Value;
disp(app.c1h1, 'b')
app.c12h12 = app.C1HI2EditField_2.Value;
elseif (app.HSV > 4 && app.HSV <= 4.75) && app.tcof <= 39548 && app.invf <=1 % Declaring conditions for result display
app.C1HI2EditField_2.Value = app.HSV * app.tcof * app.InterventionFactorEditField.Value;
disp(app.c12h12, 'b')
app.c1hi3 = app.C1HI3EditField_3.Value;
elseif (app.HSV > 4.75 && app.HSV <= 6) && app.tcof <= 39548 && app.invf <= 1
app.C1HI3EditField_3.Value = app.HSV * app.tcof * app.InterventionFactorEditField.Value;
disp(app.c1hi3, '#00FFFF')
app.c1hi4 = app.C1HI4EditField_4.Value;
elseif (app.HSV > 6 && app.HSV <= 7.25) && app.tcof <= 39548 && app.invf <= 1
app.C1HI4EditField_4.Value = app.HSV * app.tcof * app.invf;
disp(app.c1hi4, '#D95319') % displaying result and setting color background
app.c1hi5 = app.C1HI5EditField_5.Value;
elseif (app.HSV > 7.25 && app.HSV <= 15) && (app.tcof <= 39548) && (app.invf <= 1) % Declaring conditions for result display
app.C1HI5EditField_5.Value = app.HSV .* app.tcof .* app.invf;
disp(app.c1hi4, '#D95319') % displaying result and setting color background
app.c21h21 = app.C21HI21EditField_9.Value;
elseif (app.HSV <= 4) && ( app.tcof > 39548 && app.tcof <= 65907) && (app.invf <= 1) % Declaring conditions for result display
app.C21HI21EditField_9.Value = app.HSV .* app.tcof .* app.invf;
disp(app.c21h21, 'b') % displaying result and setting color background
app.c22h22 = app.C22H22EditField_10.Value;
elseif (app.HSV > 4 && app.HSV <= 4.75) && (app.tcof > 35548 && app.tcof <= 65907) && (app.invf <= 1) % Declaring conditions for result display
app.C22H22EditField_10.Value = app.HSV .* app.tcof .* app.invf;
disp(app.c22h22, 'b') % displaying result and setting color background
app.c23h23 = app.C23HI23EditField_8.Value;
elseif (app.HSV > 4.75 && app.HSV <= 6) && ( app.tcof > 35548 && app.tcof <= 65907) && (app.invf <= 1) % Declaring conditions for result display
app.C23HI23EditField_8.Value = app.HSV .* app.tcof .* app.invf;
disp(app.c22h22, '#D95319') % displaying result and setting color background
app.c24h24 = app.C24HI24EditField_7.Value;
elseif (app.HSV > 6 && app.HSV <= 7.25) && ( app.tcof > 35548 && app.tcof <= 65907) && (app.invf <= 1) % Declaring conditions for result display
app.C24HI24EditField_7.Value = app.HSV .* app.tcof .* app.invf;
disp( app.c24h24, '#D95319') % displaying result and setting color background
app.c25h25 = app.C25H25EditField_19.Value;
elseif ( app.HSV > 7.25 && app.HSV <= 15) && ( app.tcof > 35548 && app.tcof <= 65907) && (app.invf <= 1) % Declaring conditions for result display
app.C25H25EditField_19.Value = app.HSV .* app.tcof .* app.invf;
disp( app.c25h25, '#A2142F')
app.c31h31 = app.C31HI31EditField_13.Value;
elseif (app.HSV <= 4) && ( app.tcof > 65907 && app.tcof <= 100000) && (app.invf <= 1) % Declaring conditions for result display
app.C31HI31EditField_13.Value = app.HSV * app.tcof * app.invf;
disp(app.c31h31, '#4DBEEE')
app.c32h32 = app.C32HI32EditField_14.Value;
elseif (app.HSV > 4 && app.HSV <= 4.75) && ( app.tcof > 65907 && app.tcof <= 100000) && app.invf <= 1 % Declaring conditions for result display
app.C32HI32EditField_14.Value = app.HSV .* app.tcof .* app.invf;
disp(app.c32h32, '#EDB120')
app.c33h33 = app.C33HI33EditField_12.Value;
elseif (app.HSV > 4.75 && app.HSV <= 6) && (app.tcof > 65907 && app.tcof <= 100000) && (app.invf <= 1) % Declaring conditions for result display
app.C33HI33EditField_12.Value = app.HSV .* app.tcof .* app.invf;
disp(app.c33h33, '#EDB120')
app.c34h34 = app.C34HI34EditField_11.Value;
elseif (app.HSV > 6 && app.HSV <= 7.25) && (app.tcof > 65907 && app.tcof <= 100000) && (app.invf <= 1) % Declaring conditions for result display
app.C34HI34EditField_11.Value = app.HSV .* app.tcof .* app.invf;
disp(app.c34h34, '#A2142F')
app.c35h35 = app.C35HI35EditField_20.Value;
elseif (app.HSV > 7.25 && app.HSV <= 15) && (app.tcof > 65907 && app.tcof <= 100000) && (app.invf <= 1) % Declaring conditions for result display
app.C34HI34EditField_11.Value = app.HSV .* app.tcof .* app.invf;
disp(app.c35h35, 'r')
app.c41h41 = app.C41HI41EditField_17.Value;
elseif (app.HSV <= 4) && (app.tcof > 100000 && app.tcof <= 400000) && (app.invf <= 1) % Declaring conditions for result display
app.C41HI41EditField_17.Value = app.HSV .* app.tcof .* app.invf;
disp(app.c41h41, '#EDB120')
app.c42h42 = app.C42HI42EditField_18.Value;
elseif ( app.HSV > 4 && app.HSV <= 4.75) && (app.tcof > 100000 && app.tcof <= 400000) && (app.invf <= 1) % Declaring conditions for result display
app.C42HI42EditField_18.Value = app.HSV .* app.tcof .* app.invf;
disp(app.c42h42, '#A2142F')
app.c43h43 = app.C43HI43EditField_16.Value;
elseif (app.HSV > 4.75 && app.HSV <= 6) && ( app.tcof > 100000 && app.tcof <= 400000) && (app.invf <= 1) % Declaring conditions for result display
app.C43HI43EditField_16.Value = app.HSV .* app.tcof .* app.invf;
disp(app.c43h43, 'r')
app.c44h44 = app.C44HI44EditField_15.Value;
elseif (app.HSV > 6 && app.HSV <= 7.25) && ( app.tcof > 100000 && app.tcof <= 400000) && (app.invf <= 1) % Declaring conditions for result display
app.C44HI44EditField_15.Value = app.HSV .* app.tcof .* app.invf;
disp(app.c44h44, 'r')
app.c45h45 = app.C45HI45EditField_21.Value;
elseif ( app.HSV > 7.25 && app.HSV <= 15) && (app.tcof > 100000 && app.tcof <= 400000) && (app.invf <= 1) % Declaring conditions for result display
app.C45HI45EditField_21.Value = app.HSV .* app.tcof .* app.invf;
disp(app.c45h45, 'r')
else
app.RIResult.Value = 'Result out of range';
disp( app.RIResult.Value )
end
The code is not working.
  2 Comments
Alfred Amiolemen
Alfred Amiolemen on 3 Aug 2019
@Walter Roberson, thanks for the question. If for instance any of the conditions are met, maybe app.HSV = 3, and app.tcof = 30000, the error will indicate on that particular line of code. If its another line meet the condition, the error didplay on the particular line that meet the condition and so on. I have tried for loop and while statements I dont know why it has refused to work.

Sign in to comment.

Accepted Answer

dpb
dpb on 3 Aug 2019
app.HSV =0:15; % app.HSV
app.tcof = 0:400000;
app.invf =0:1;
are all vectors, not scalars. Short circuit operators only operate on scalar quantities is what is triggering the error message.
>> app.HSV =0:15;
>> app.HSV > 0 && app.HSV <= 4
Operands to the || and && operators must be convertible to logical scalar values.
>> app.HSV > 0 & app.HSV <= 4
ans =
1×16 logical array
0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0
>>
  5 Comments
Walter Roberson
Walter Roberson on 4 Aug 2019
Time to use the debugger. Put a breakpoint in just after the numeric field is retrieved, examine it, and then start single-stepping until you find the problem.

Sign in to comment.

More Answers (0)

Categories

Find more on Install Products in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!