MATLAB Answers

Interpolation error: Unable to perform assignment because the size of the left side is not the same as the size of the right side.

2 views (last 30 days)
Andreas Polydorides
Andreas Polydorides on 25 Sep 2019
Commented: Adam on 25 Sep 2019
I am trying to work with a .mat file.
It contains a structure of 2 container.Map elements, one name trajs and the other emgs.
Data in emgs has a sampling frequency of 20kHz whereas data in trajs has a sampling frequency of 1kHz. As such I want to upsample the data in trajs.
trajs contains 19 cell arrays (19 keys and 19 values) with each value cell being a {680x3 double}.
I have never worked with containers.Map, cell arrays or interpolation for that matter so any help or tips would be greatly appreciated.
D = load('005_Stair11.mat');
markers = keys(D.trajs);
coords = values(D.trajs);
for i = 1:19
for j = 1:3
coords{i}(:, j) = interp(coords{i}(:, j),20);
This yiels the error 'Unable to perform assignment because the size of the left side is 680-by-1 and the size of the right side is 13600-by-1.' which I know is from the pre-determined size of the matrix but how would I go about it without having to make new matrices which as I understand is relatively time-consuming in Matlab.

  1 Comment

Adam on 25 Sep 2019
Well, since you're increasing size from 680 to 13600 anyway I doubt resizing your existing matrix is going to be much (if any) faster than just creating a new one. You still have to assign all the new memory.
You can try inserting something like
coords{i} = zeros( 13600, 3 );
before the interp command, though I would never hard-code the size like that. More like
interpMultiple = 20;
coords{i} = zeros( size( coords{i}, 1 ) * interpMultiple, size( coords{i}, 2 ) )
but such details don't really matter if it isn't any better than simply letting it create a new matrix anyway.

Sign in to comment.

Answers (0)

Sign in to answer this question.