I have to run following with eval function in a single line.
a = 1:20; % first step is to define a variable
b = '[nan a(2:end)]'; % then index should be used. This should be in a single line.
c = eval(b);
My proposal is (which is wrong);
>> b = 'a = 1:20; [nan a(2:end)]'; % I need a single line such this
>> c = eval(b)
Error: The expression to the left of the equals sign is not a
valid target for an assignment.
There are some suggestions not to use eval. I have to use. Any help apreciated!

 채택된 답변

Walter Roberson
Walter Roberson 2015년 10월 29일

0 개 추천

You cannot return a value from eval().
Does the assignment specifically require you to use eval()? We firmly discourage the use of eval().

댓글 수: 4

I think I have to use it. Walter, will following code always work?
eval(b);
c = ans;
Walter Roberson
Walter Roberson 2015년 10월 29일
I do not know if it will always work; it might work.
Could you post a copy of the assignment text?
>> b = 'a = 1:20; [nan a(2:end)]'; % I need a single line such this
>> eval(b)
>> c = ans;
Walter Roberson
Walter Roberson 2015년 10월 29일
Right. Please post the text of the assignment.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Entering Commands에 대해 자세히 알아보기

질문:

2015년 10월 29일

댓글:

2015년 10월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by