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 comentario

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.

Iniciar sesión para comentar.

 Respuesta aceptada

Jan
Jan el 22 de Ag. de 2017
Editada: Jan el 22 de Ag. de 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.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 22 de Ag. de 2017

Editada:

Jan
el 22 de Ag. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by