Effacer les filtres
Effacer les filtres

Calling Variables from the Workspace

3 vues (au cours des 30 derniers jours)
Chinwe Orie
Chinwe Orie le 28 Juin 2018
Réponse apportée : OCDER le 28 Juin 2018
Hello. I have some variables in the workspace and they are named Cap# (the # stands for a number, so it could be 1,2,3,etc.). I want to create a loop so I can plot each variable from that workspace. They all differ by the number (Cap1, Cap2, Cap3, etc.). At the moment, I have to plot each variable manually and because there are many of them it is not efficient. Is there a way to just plot each one using a loop?

Réponse acceptée

OCDER
OCDER le 28 Juin 2018
Go back to your variable creation, and change all your variable creation to Cap{#}.
Example:
Cap1 = [ 1 2 3 4 5] ==> Cap{1} = [ 1 2 3 4 5];
Cap2 = [ 1 2 3 4 5] ==> Cap{2} = [ 1 2 3 4 5];
Cap3 = [ 1 2 3 4 5] ==> Cap{3} = [ 1 2 3 4 5];
...
Then you can do your loop like:
for j = 1:length(Cap)
plot(Cap{j});
end
You're facing difficulty now because you've named your variables incorrectly like Cap1, Cap2, etc. Read this:

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by