How can you extend a vector with the last value?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Bruno Luong
2022-10-14
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)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multirate Signal Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
