How do i convert a sentence of string numbers into multiple doubles

4 次查看(过去 30 天)
Hello guys! Im kinda new with using the GUI for MATLAB, and I have a school project which needs a GUI that accepts transfer functions and plot their unit step plot (impulse(cs,rs)), to verify their Kp, Kv, Ka.
I'm trying to a GUI that accepts a transfer function but i dont know how to implement it. I decided that i'll use an editbox to input the numeric values for the transfer function's num and denom, using this:
x = str2double(get(handles.edit1, 'string'));
y = str2double(get(handles.edit2, 'string'));
set(handles.text2, 'string', x)
sys1=tf([x],poly([y]))
so far it accepts only one number in the numerator and denominator i wanted to be able to input something like this:
>> sys1=tf([20 20],poly([-4 -3]))
sys1 =
20 s + 20
--------------
s^2 + 7 s + 12
  1 个评论
Janno Rhey Don
Janno Rhey Don 2020-7-23
update i tried using str2num used in at the numerator of the tf() and it worked but it somehow doesnt work on the denominator, any ideas on why this is the case?
FP = str2num(get(handles.edit1, 'string'));
ca = str2num(get(handles.edit3, 'string'));
sys1=tf(FP,poly(ca))
sys1a=feedback(sys1, 1, -1);
rs=tf([1], [1 0]);
cs= rs*sys1a;
axes(handles.axes1);
impulse(cs,rs);
grid on
ERROR message:
Error using str2num (line 35)
Input must be a character vector or string scalar.
Error in testing>pushbutton1_Callback (line 132)
ca = str2num(get(handles.edit3, 'string'));
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in testing (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)testing('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2020-7-23
You configured edit3 to have Max that is greater than 1, and the user entered more than one line.
The user did not just enter spaces between the numbers: they would have had to press return between numbers for this to have happened... and it cannot happen if Max is at its default 1.
(Exception: if you initialized edit3 String property to multiple cell entries, then if Max was set to 1, then it would have given a warning and refused to render the box for the control, but getting its String property would have returned the multiple cell entries. This is the exception to the rule that Max must have been greater than 1 and the user entered multiple lines -- the case where you yourself initialized the control that way.)
  1 个评论
Janno Rhey Don
Janno Rhey Don 2020-7-23
Hello thank you for the reply, i have now fixed the numerator denominator part and can know plot the whole function my problem at the moment is getting the limit s->0, of the transfer function that i defined using:
sysa=tf [ 20 20], poly[-4 -3]));
i tried using limit(sysa); but it said "Undefined function 'limit' for input arguments of
type 'tf'."

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by