adding strings per component
1 回表示 (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
採用された回答
Azzi Abdelmalek
2014 年 11 月 29 日
This is not a good idea, read this http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
6 件のコメント
Azzi Abdelmalek
2014 年 11 月 29 日
velocity=s(:,1);
position=s(:,2);
out=table(velocity,position)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!