How can I find the second last value of a vector?
22 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Is there a command that returns the second last value in a value. For example, in vector W = [1 2 3 4...n], W(end) returns n, how would I return the n-1 value? Thanks
0 commentaires
Réponse acceptée
David Fletcher
le 3 Avr 2018
W(end-1)
2 commentaires
Joseph Anchores
le 22 Août 2021
I just tried this and matkab says "Array indices must be positive integers or logical values."
DGM
le 22 Août 2021
What size is your variable? If you are indexing along a dimension of length 1, then you will end up trying to access the zeroth subscript -- which is not valid.
A = 27;
A(1)
A(end)
A(end-1)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!