How to include 'end' in a varibable to extract a subset of the original vector ?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
giulio benedini
le 16 Juil 2021
Commenté : giulio benedini
le 16 Juil 2021
vector = 1:200;
%i want to extract a subset of vector
vector1 = vector(1:end-18)
%but if define a separate variable (range)
range =[1:end-18];
vector1 = vector(range);
%i got this:
Error: File: Untitled Line: 4 Column: 11
Illegal use of reserved keyword "end".
how can i define range in order to not have an error?
0 commentaires
Réponse acceptée
Stephen23
le 16 Juil 2021
"... if i want to define range before the definictiion of the vector..."
You could use an anonymous function:
rng = @(v)v(1:end-18); % range is defined!
vec = 1:200;
out = rng(vec)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Semiconductors and Converters dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!