필터 지우기
필터 지우기

Function 'subs': how use?

조회 수: 1 (최근 30일)
JRC
JRC 2013년 8월 21일
I have realized that the counts with this function 'subs' doing x(1) +1*x(2) and x(1) + 1*x(2) are differents, for example. The space in these expressions give me results differents.
Which the problem?
Which is correct? I think that the correct is x(1) +1*x(2) and not with the space.
Thanks.
JRC

답변 (1개)

Walter Roberson
Walter Roberson 2013년 8월 21일
In the context of the [] operation,
x(1) +1*x(2)
would usually be interpreted as
(x(1)), (+1*x(2))
which is two entries.
x(1) + 1*x(2)
inside [] would be interpreted as one entry.
If you are not within the context of [] then the two should be the same.
  댓글 수: 5
Walter Roberson
Walter Roberson 2013년 8월 21일
Do not eval() MuPAD expressions, such as are returned by sym() or subs(). MuPAD and MATLAB use different syntax rules and different operators. If you want to convert a MuPAD expression into executable MATLAB form, use matlabFunction() on the MuPAD expression -- but if you do not need to execute at the MATLAB level, keep expressions in MuPAD form. If you have a MuPAD expression which consists entirely of constants and you want to convert it to double precision, use double() on the MuPAD expression.
Please see also http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F . It looks to me as if you would be better off storing values in a struct than using eval() to generate new variable names.
JRC
JRC 2013년 8월 21일
Thanks Walter.

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

Community Treasure Hunt

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

Start Hunting!

Translated by