필터 지우기
필터 지우기

Creating a string with sprintf() and assign a variable to it

조회 수: 4 (최근 30일)
Dimitris M
Dimitris M 2012년 8월 13일
Hello
I have a basic question which I can not solve. I am creating multiple variables with sprintf and I would be interested to assign an array to each of them.
I tried to do it in some ways but did not work. Is there any way to do it ?
Thank you in advance

채택된 답변

Honglei Chen
Honglei Chen 2012년 8월 13일
편집: Honglei Chen 2012년 8월 13일
Don't know what you are trying to do but here is an example.
eval(sprintf('A%d = %s',1,'magic(3)'))
As a general rule though, you should avoid using variables such as A1, A2, (you may not have this issue, I just put it as a precaution), see
  댓글 수: 2
Dimitris M
Dimitris M 2012년 8월 13일
Thank you very much
I was trying the same thing but in wrong way !!!
I was doing something like
eval(sprintf('Variable_%d',5))=100;
Which did not seem to work !!!!
Thank you anyway !!!
Walter Roberson
Walter Roberson 2012년 8월 13일
Using eval() very often leads to problems in coding and debugging. It is much better to use one of the alternatives such as cell arrays.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Manual Performance Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by