Error: Subscripted assignment dimension mismatch.
1 view (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Stephen23
on 21 Mar 2016
Edited: Stephen23
on 21 Mar 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;
0 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!