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

2 次查看(过去 30 天)
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

采纳的回答

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

更多回答(1 个)

Walter Roberson
Walter Roberson 2018-7-7
编辑:Walter Roberson 2018-7-7
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.

类别

Help CenterFile Exchange 中查找有关 Graphics Objects 的更多信息

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by