How to want to define a matrix whose name is a value of another variable

조회 수: 4 (최근 30일)
Saurabh Srivastava
Saurabh Srivastava 2013년 4월 8일
댓글: Walter Roberson 2014년 1월 3일
I have a variable which contains some character data and now I want define a matrix with the same character data by using the variable. for example let variable V='abc' and now I want to define a matrix with name abc using variable V. The code which I am using is
V='abc'; u=rand(3); V=u;
Now I want that u should be assign to 'abc' but the above code actually redefine the variable V. Hope I have put my point.

답변 (2개)

Walter Roberson
Walter Roberson 2013년 4월 8일

Iman Ansari
Iman Ansari 2013년 4월 8일
Hi
V='abc'; u=rand(3);eval([V '=u']);
  댓글 수: 2
Saurabh Srivastava
Saurabh Srivastava 2014년 1월 3일
This does not work. Error msg (Index exceeds matrix dimensions)
Walter Roberson
Walter Roberson 2014년 1월 3일
You might have accidentally defined "rand" or "eval" as variables.
In any case this approach is not recommended; please see the link I posted.

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

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by