MATLAB Answers

Fill NaN matrix with vector of unequal sizes

3 views (last 30 days)
Hi all,
I have the following code:
temp = {'AccNorm','GyrNorm'};
NSensors = 5;
for a = 1:length(temp)
for k = 1:NSensors
CMC_RT(k).RF.(temp{a}) = nan(10,2);
In which I just preallocate CMC_T with NaN values, because the 2 vectors I want to put in the matrix have different lengths.
However when I try to fill them up:
for a = 1:length(temp)
for k = 1:NSensors
CMC_RT(k).RF.GyrNorm = CMC_RTT.RF.(temp{a})(k,1:10)';
CMC_RT(k).RF.GyrNorm(:,2) = CMC_RTT.RF.(temp{a})(k,11:19)';
Matlab gives me the error: Unable to perform assignment because the size of the left side is 10-by-1 and the size of the right side is 9-by-1.
Which obviously makes sense, but I would think matlab would just fill the NaN matrix with the numbers and leave the NaN values for the ones where there is no substitute value. But this was apparently whishful thinking...
Any help on a idea for a solution would be much appreciated.
Thank you!


Sign in to comment.

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 18 Oct 2019
CMC_RT(k).RF.GyrNorm(1:10,1) = CMC_RTT.RF.(temp{a})(k,1:10);
CMC_RT(k).RF.GyrNorm(1:9,2) = CMC_RTT.RF.(temp{a})(k,11:19);
The complex conjugates are not required.

  1 Comment

Inti Vanmechelen
Inti Vanmechelen on 18 Oct 2019
Very very very stupid of me to not think of doing that myself.
Thank you.

Sign in to comment.

More Answers (0)