0
votes

I am trying to add a number of vectors in a Matrix where each row represents a vector, but it gives me "Subscripted assignment dimension mismatch." error. The main problem is that each vector has a different size. I tried to add zeros at the end of the short vectors but I couldn't do it. Any Help.

Example:

%signal is a vector of data.
[x(1,:),y(1,:)] = findpeaks(signal1);
[x(2,:),y(2,:)] = findpeaks(signal2); %error as the peaks count in signal 2 is not the same as in signal 1. 
1

1 Answers

0
votes

OK, given two vectors of unequal length,

A=rand(1,10)
B=rand(1,5)

the proper way to deal with this is to use a cell array

D={A;B}

And then you can get whatever elements you want like this, for example:

D{1}(1:3) %// A(1:3)

If you don't want to use cells, you can add rows using this little function that adds row vector M to matrix F

addRow=@(F,M) [F NaN(size(F,1),size(M,2)-size(F,2));M NaN(1,size(F,2)-size(M,2))]

you would use it like this:

F=A
F=addRow(F,B)