how can a plot a function given by the user in app design?
조회 수: 3 (최근 30일)
이전 댓글 표시
I am developing an application that will allow to graph two imput signals given by the user and then calculate and graph the convolution of these, however, I do not know how I could read the function entered by the user in the text field to be able to graph it, i understand that it reads it as a string and i need to convert it somehow to a expression. I appreciate any help or advice, this is my first time trying app designer so I'm a bit lost.
Here I leave the part of the code where I'm having problems.
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure % UI Figure
LabelEditField matlab.ui.control.Label % x(t)
FInput matlab.ui.control.EditField % sin(pi*t...
LabelEditField2 matlab.ui.control.Label % h(t)
SInput matlab.ui.control.EditField % t./t
Start matlab.ui.control.Button % Start
xt matlab.ui.control.UIAxes % First Input
yt matlab.ui.control.UIAxes % Second I...
LabelNumericEditField matlab.ui.control.Label % x1
x1range matlab.ui.control.NumericEditField % [-Inf Inf]
Label matlab.ui.control.Label % x2
x2range matlab.ui.control.NumericEditField % [-Inf Inf]
Label2 matlab.ui.control.Label % h1
h1range matlab.ui.control.NumericEditField % [-Inf Inf]
Label3 matlab.ui.control.Label % h2
h2range matlab.ui.control.NumericEditField % [-Inf Inf]
Label4 matlab.ui.control.Label % t1
t1 matlab.ui.control.NumericEditField % [-Inf Inf]
Label5 matlab.ui.control.Label % t2
t2 matlab.ui.control.NumericEditField % [-Inf Inf]
NumericEditField matlab.ui.control.NumericEditField % [-Inf Inf]
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
end
% Start button pushed function
function StartButton(app)
%Initialization
t0 = app.t1.Value;
tf = app.t2.Value;
t = t0:tf; %Time Range
X = zeros(1,length(t)); % First Input signal
x1 = app.x1range.Value;
x2 = app.x2range.Value; % Range of Input Signal
H = zeros(1,length(t)); % Second Input signal
h1 = app.h1range.Value;
h2 = app.h2range.Value; % Range of Second Input Signal
Y = zeros(1,length(t)); % Convolution output
xh1 = x1+h1;
xh2 = x2+h2; % Range of Convolution output
%Input Signals
x = app.FInput.Value;
x(t==0)=1; % Generate First Input (Sinc default)
h = app.SInput.Value;
h(t==0)=1; % Generate Second Input (Impulse Response default)
%H(t>=h1&t<=h2) = h(t>=h1&t<=h2); % Fit First Input signal within range
X(t>=x1&t<=x2) = x(t>=x1&t<=x2); % Fit Second Input within range
%Plot Input Signals
plot(app.xt,t,X,'b')
end
end
댓글 수: 0
답변 (1개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!