How can I define a variable with separate variables for later use?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
% simply an example
car = [a b c]
a = 2
car(1)
I want this to return 2 but it cannot even define car because a b and c are undefined. Is there a way to define car using variables like a b and c which can be defined later?
% an attempted fix that did not work
a = 1; b = 1; c = 1;
car = [a b c]
a = 2;
car(1)
this returns 1 because car was defined from the a which was 1 but I want a to be dynamic inside of car such that this would return 2. Help please!
2 commentaires
Optics Wizard
le 9 Avr 2020
Not really, but this might help:
You can assign value to car(1), for instance:
car(1) = 2;
So if you want to define 100 empty variables for later use, you can just write:
variables = zeros(1,100);
Then when you want to populate all the variables:
for n = 1:100
variables(n) = rand();
end
Is that sufficient?
Réponses (0)
Voir également
Catégories
En savoir plus sur Elementary Math 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!