필터 지우기
필터 지우기

How to request input and set as symbols?

조회 수: 2 (최근 30일)
David Hagan
David Hagan 2012년 2월 10일
I am attempting to write a code for the Newton-Raphson method which essentially solves a system of n equations and n unknowns. I am trying to ask for user input (in the form of equations, initial values, etc.). As far as I know, I have to set the variables to symbols.
How can I request the user input for the variables to be used before asking for the equations?
in = 1;
data = [];
i = 1;
while in ~= 0
var_string(i) = input('What variables are you using? End with "end" ','s');
if var_string(i) == 'end'
break;
else
variable(i) = sym(var_string(i))
i = i + 1;
end
end
This is what I have at this point. Is there a way to do this? Thanks.

채택된 답변

Walter Roberson
Walter Roberson 2012년 2월 10일
input() is going to return a string, not a cell array. Unless the string happens to be only a single character long, it is not going to fit in to var_string(i) . Switch to cell arrays for var_string .
Also, do not use == to compare strings. For example,
'hi' == 'end'
is going to give you an error about inconsistent dimensions. Use one of the string comparison functions.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by