Problem with Empty matrix: 1-by-0

1 view (last 30 days)
SreeHarish Muppirisetty
SreeHarish Muppirisetty on 20 Aug 2013
My variables and their values, in the 'If' condition statement
leftoverROI1s{1}= [11 15];
missinglabelsinimage{1} is an empty matrix.
I want to execute a 'for' loop only if both my conditions in the 'if' statement are true, i.e.,: if((~isempty(leftoverROI1s{1})) && (~isempty(missinglabelsinimage{1})))
for % loop for each element in non-empty missinglabelsinimage structure array. Add a scalar to each element of non-empty missinglabelsinimage structure array
end % end for loop
end % end if
My program control is going into for loop (which I expect, it shouldn't if there is an empty missinglabelsinimage{1}) and the control is working on 'missinglabelsinimage{1}' (empty matrix), which obviously gives me an error as I am trying to add a scalar to my 'non-empty' missinglabelsinimage{1}.
I am not able to understand the error in my if condition. Any help would be appreciated.
Thanks in advance for your time
Best
Harish
  1 Comment
SreeHarish Muppirisetty
SreeHarish Muppirisetty on 22 Aug 2013
I did the following checks:
(~isempty(missinglabelsinimage{1}))
ans =
0
(~isempty(leftoverROI1s{1}))
ans =
1
missinglabelsinimage{1}
ans =
Empty matrix: 1-by-0

Sign in to comment.

Answers (1)

Iain
Iain on 20 Aug 2013
Before the if statement, add
disp(~isempty(leftoverROI1s{1}))
disp(~isempty(missinglabelsinimage{1}))
If both turn up with "1", you'll go into the loop. I suspect that missinglabelsinimage{1} contains a 1x1 cell array with an empty in it.
  1 Comment
SreeHarish Muppirisetty
SreeHarish Muppirisetty on 20 Aug 2013
Hi,
I did the following checks:
(~isempty(missinglabelsinimage{1}))
ans =
0
(~isempty(leftoverROI1s{1}))
ans =
1
missinglabelsinimage{1}
ans =
Empty matrix: 1-by-0

Sign in to comment.

Categories

Find more on Loops and Conditional Statements 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!