Assignment has more non-singleton rhs dimensions than non-singleton subscripts

2 views (last 30 days)
Why do i keep on getting this error code? The code executes well and the matrix gets populated with the right elements. It does what it supposed to but at the end spits out the error code.
filename = 'testGUI';
[num txt raw] = xlsread(filename,2);
%
clc
sz = size(txt)
row = sz(1);
column = sz(2);
for i = 1 : row
for j = 1 : column
idx(i,j) = find(not(cellfun('isempty', txt(i,j))))
end
end

Accepted Answer

erick Del Real
erick Del Real on 7 Jul 2018
Thank you very much! that worked great!

More Answers (1)

Walter Roberson
Walter Roberson on 7 Jul 2018
Edited: Walter Roberson on 7 Jul 2018
You are passing individual txt(i,j) into cellfun('isempty') . Any one entry is either empty or not empty, so 1 (true, it is empty) or 0 (false, it is not empty) will be returned for any one call. You are then applying not() to that scalar 1 (is empty) or scalar 0 (is not empty), getting back 0 (is not empty is false because it is empty) or 1 (is not empty is true). You then apply find() to that scalar 0 or 1 value. In the case of the scalar 0 (was empty) the find will fail and the empty vector will be returned. In the case of the scalar 1 (was not empty) the find will work and the scalar 1 will be returned. So in one case it will return empty and the other case it will return 1. But your code expects that it will always return a scalar.
if what you want to create a logical array showing whether the entries in txt are empty (0) or not (1) then you would just use
idx = not( cellfun('isempty', txt) );
with no looping.

Categories

Find more on Graphics Objects in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!