adding strings per component

1 vue (au cours des 30 derniers jours)
cgo
cgo le 29 Nov 2014
Commenté : cgo le 29 Nov 2014
Hi,
I have the following code:
for n = 1:4
velocity = ['v_',num2str(n),' = n*2'];
eval(velocity)
position = ['x_', num2str(n), '= n.^2'];
eval(position)
end
So, the expected output would be: v_1 = 2, x_1 = 1 \\ v_2 = 4, x_2 = 4 \\ … \\ v_4 = 8, x_4 = 16.
Let's say we want to do something to the components. For example, add v_1 + x_1, (we want to do something to variables with the same index.) How do we do that?

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 29 Nov 2014
  6 commentaires
Azzi Abdelmalek
Azzi Abdelmalek le 29 Nov 2014
You can also use table
velocity=s(:,1);
position=s(:,2);
out=table(velocity,position)
cgo
cgo le 29 Nov 2014
Thanks again.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by