How can I change the name of a variable?

1 ビュー (過去 30 日間)
Bob 2016 年 7 月 30 日
回答済み: Azzi Abdelmalek 2016 年 7 月 30 日
I want to change the name of a variable, X which is the output from my simulink model, according to my input variable, np.
For example:
for i=1:2
np = input(':'); % let's say, for i=1 , np=50
sim('Simulink_Model'); % Output: X
sprintf('X%d',np) = X; % Now I want the output X to be X50

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 7 月 30 日
Read this you will know that it's not a good idea to create such name variables, you can just use one cell array
for ii=1:2
sim('Simulink_Model'); % Output: X
out{ii} = X;


Find more on Loops and Conditional Statements in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by