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 Commento

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.

Accedi per commentare.

 Risposta accettata

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.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Richiesto:

il 22 Ago 2017

Modificato:

Jan
il 22 Ago 2017

Community Treasure Hunt

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

Start Hunting!

Translated by