Assignment has more non-singleton rhs dimensions than non-singleton subscripts
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
erick Del Real
le 6 Juil 2018
Réponse apportée : erick Del Real
le 7 Juil 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 commentaires
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 7 Juil 2018
Modifié(e) : Walter Roberson
le 7 Juil 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 commentaires
Voir également
Catégories
En savoir plus sur Graphics Objects dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!