Error: Subscripted assignment dimension mismatch.

1 次查看(过去 30 天)
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?

采纳的回答

Stephen23
Stephen23 2016-3-21
编辑:Stephen23 2016-3-21
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;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by