Effacer les filtres
Effacer les filtres

Compensate the vector with the last entry

1 vue (au cours des 30 derniers jours)
mingcheng nie
mingcheng nie le 25 Avr 2023
I have a length L vector contains some numbers, I want to compensate this vector to length K, where K > L, with repeating the last entry of the vector. For example, the vector is [2 4 7 3], after compensate, it will be [2 4 7 3 3 3 3 3]. I hope there is an efficient way to do so because I actually have more than 10^4 vectors to compensate.
Thanks,
  1 commentaire
Stephen23
Stephen23 le 25 Avr 2023
"I hope there is an efficient way to do so because I actually have more than 10^4 vectors to compensate."
Do you really have 1e4 separate vectors stored in the workspace? How did you get them all there?

Connectez-vous pour commenter.

Réponses (1)

Stephen23
Stephen23 le 25 Avr 2023
V = [2,4,7,3];
K = 8;
V(end+1:K) = V(end)
V = 1×8
2 4 7 3 3 3 3 3

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Produits


Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by