Change variable's names with one character?

조회 수: 1 (최근 30일)
pauldjn
pauldjn 2020년 1월 5일
편집: Stephen23 2020년 1월 5일
Hi. Suppose I have these variables:
a=1
b=2
c=3
And I want to change their names by adding the number assigned here:
x = 1
So I will have:
a1= 1
b1= 2
c1= 3
Is possible to do that without a loop?
Thanks
  댓글 수: 1
Stephen23
Stephen23 2020년 1월 5일
편집: Stephen23 2020년 1월 5일
There are certainly ways to do this, if you want to force yourself into writing slow, complex, buggy code that is hard to debug:
Much better is to learn how to use arrays and indexing, just like experienced MATLAB users. Indexing is neat, simple, easy to debug and very efficient. Unlike what you are trying to do.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2020년 1월 5일
편집: Image Analyst 2020년 1월 5일
Yes
a1 = a;
b1 = b;
c1 = c;
x is unneeded, as per this answer: Click here
Note though that a1 and a do not refer to the same memory location so changing a1 will not automatically change a, and changing a will not automatically change a1.
  댓글 수: 1
pauldjn
pauldjn 2020년 1월 5일
Thanks for your answer, though this solution is aplicable for the 3 variables I'm actually looking a way to do it for dozen of variables, thats why I used x=1 so if I changed x I can use it to modify multiple variable names at once.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Variables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by