How can you extend a vector with the last value?
2 views (last 30 days)
Show older comments
Hi,
I have two vectors with different dimensions. Vector X is 1x5, the other vector A has the dimension 1x3.
Now I want to plot(X,A), but because of the different dimensions of the vectors this obviously doesn't work.
A solution that would work for me is to take the last value of A and extend the vector to a 1x5 format so that the 4th and 5th value is the same as the last value (in this case the 3rd).
So it should look something like
A = ( 1 A_new = (1
2 ---> 2
3) 3
3
3)
This is only supposed to serve as an example, in my real problem the dimensions are like 1x92000. That's why putting in the values by hand would be very time-consuming.
I would love some help for this question, thanks in advance!
1 Comment
Bruno Luong
on 14 Oct 2022
Instead of extend with last value, which is an emperical extension, why not fill with NaN, so that the non-exsiating data is not plotted
X = 1:10;
A = rand(1,5);
A_pad = A;
A_pad(end+1:length(X)) = NaN;
plot(X, A_pad)
See Also
Categories
Find more on Multirate Signal Processing 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!