Incorrect use if/else

1 view (last 30 days)
Alberto Acri
Alberto Acri on 11 Jan 2023
Commented: Walter Roberson on 11 Jan 2023
Hi. How can I make the following if/else work ?
cell = {[],[],[]};
cell1 = {rand(1452,2),[],[]};
A = cell{1,1};
B = cell1{1,1};
if A = []
B(:,2)=[];
else
....
end

Accepted Answer

Star Strider
Star Strider on 11 Jan 2023
Perhaps this —
cell = {[],[],[]};
cell1 = {rand(1452,2),[],[]};
A = cell{1,1};
B = cell1{1,1};
if isempty(A)
B(:,2)=[];
else
% What do you want to do here?
end
B
B = 1452×1
0.4969 0.7029 0.9556 0.4312 0.7830 0.4565 0.6727 0.7772 0.8387 0.8329
.
  1 Comment
Walter Roberson
Walter Roberson on 11 Jan 2023
Note that matlab uses == for comparisons.
Exception: if you use a comparison in a symbolic expression, especially a piecewise expression, then the visual representation when you display it might use = instead of == . The visual representation of symbolic expressions is not always valid input to matlab or to the internal symbolic engine either.

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!