How to plot vectors within in a for loop using a variable?
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
shatha almarri
le 14 Fév 2021
Réponse apportée : Jan
le 14 Fév 2021
I have some coloumn vectors in my workspace named x1, x2, x3 and y1, y2, y3
I want to make a for loop to plot x,y for each of these, im not sure of how the syntax should be but would something like this be possible:
for i = 1:3
plot (x(i), y(i)) *** not sure how this line should look (i want to plot x1 vs y1 then in the second loop plot x2 vs y2 etc...)
hold on
end
0 commentaires
Réponse acceptée
Walter Roberson
le 14 Fév 2021
x = {x1, x2, x3} ;
y = {y1, y2, y3} ;
for i = 1:3
plot(x{i} , y{i}) ;
hold on
end
0 commentaires
Plus de réponses (1)
Jan
le 14 Fév 2021
See: TUTORIAL: EVAL
Using variables called x1, x2, ... hides an index in the names. Don't do this, because it is a shot in your knee. Use indices instead: x{1}, x{2}, ...
Then see the code Walter has suggested.
0 commentaires
Voir également
Catégories
En savoir plus sur Graphics Performance 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!