Error: Subscripted assignment dimension mismatch.

1 visualización (últimos 30 días)
pamela sulis
pamela sulis el 21 de Mzo. de 2016
Editada: Stephen23 el 21 de Mzo. de 2016
Hi, I have a struct semanticTrajCompact: after traspose the content in every cell of semanticTrajCompact(1,4).locID, I want to delete consecutive repeated values. I have create this code:
for j=1:size(semanticTrajCompact(1,4).locID,1)
y=semanticTrajCompact(1,4).locID{j,1}'
newY=y([1,diff(y)]~=0)
z(j,1)=newY
end
but it gives me this error:
Subscripted assignment dimension mismatch.
Error in a (line 4)
z(j,1)=newY
I don't understand why, can you help me?

Respuesta aceptada

Stephen23
Stephen23 el 21 de Mzo. de 2016
Editada: Stephen23 el 21 de Mzo. de 2016
Because j is a scalar then z(j,1) refers to one element of z. There is nothing preventing newY from having multiple values (in fact this seems to be the point of your code). So you are trying to fit multiple elements into one element. Thus the error.
Basically you are doing this:
>> X(1,1) = 1:3
Subscripted assignment dimension mismatch.
Because multiple numeric elements do not fit into one numeric element.
You might like to use a cell array instead:
z{j,1} = newY;

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by