Assignment has more non-singleton rhs dimensions than non-singleton subscripts
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
erick Del Real
am 6 Jul. 2018
Beantwortet: erick Del Real
am 7 Jul. 2018
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

0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Walter Roberson
am 7 Jul. 2018
Bearbeitet: Walter Roberson
am 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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Graphics Objects finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!