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

Hi guys, trying my best to battle through some code but cannot get it to work for my data.
for e = length(WAV(:,1));
k = find(tss==WAV(e,1));
WAV(e,5) = dir(k);
end
WAV is currently 50x3 double, tss is 1048576x1 double, as is dir. e = 50.
Many thanks guys

1 commentaire

Today I've selected your code and pressed the "{} Code" button, to make it readable. Please do this by your own in the future. Thanks.

Connectez-vous pour commenter.

 Réponse acceptée

Jan
Jan le 22 Août 2017
Modifié(e) : Jan le 22 Août 2017
Perhaps you mean:
for e = 1:size(WAV, 1)
k = (tss == WAV(e,1));
WAV(e,5) = dir(k);
end
  1. size(X,1) is more efficient than creating a vector only to measure its length by length(X(:,1).
  2. The for loop requires a start points: "1:n". With only "for k = size(WAV,1)" the loop runs over one index only
  3. I've omitted the find() to use the faster logical indexing.
  4. "dir" is a bad name for a variable, because it shadows the builtin function with the same name. This is not an error, but it causes troubles frequently, when the user wants to access the command again.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Question posée :

le 22 Août 2017

Modifié(e) :

Jan
le 22 Août 2017

Community Treasure Hunt

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

Start Hunting!

Translated by