MATLAB Answers

dynamic variables

59 views (last 30 days)
AYAH
AYAH on 14 Feb 2012
Edited: Laura Pop on 15 Oct 2013
hello every body , who know how to name variables dynamically such as X1, x2,X3,...Xn in for loop

Accepted Answer

Benjamin Schwabe
Benjamin Schwabe on 14 Feb 2012
Hi AYAH,
why do you want to do this, you really might want to use a vector with X(1),X(2),...,X(10), they are dynamic in MatLab, so there is nothing to worry about this. And cases are really rare, in which you want to do what you'd like to have...
However, you can do it by using assignin, e.g. like that:
n=10;
for k=1:n
varname=['X',num2str(k)];
assignin('caller',varname,k)
end
  1 Comment
AYAH
AYAH on 15 Feb 2012
Thank you very much

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 14 Feb 2012
  3 Comments
AYAH
AYAH on 16 Feb 2012
Thanks alot

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!