MATLAB SIMULINK 7 - GRAPHICAL USER INTERFACE Instrukcja Użytkownika Strona 273

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 500
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 272
UI That Accepts Parameters and Generates Plots
9-27
In this figure, the two plots reflect the last successful set of inputs, f1 = 31.41, f2
= 120, and t = [1 2 3 4 5 7 9]. The time vector [1 2 6 4 5 7 9] appears
highlighted so that you can enter a new, valid, value. The highlighting results from
executing the command uicontrol(hObject) in the preceding code listing.
Plot Push Button Behavior
When you click the Plot button, the plot_button_Callback performs three basic
tasks: it gets input from the edit text components, calculates data, and creates the two
plots.
Get Input
The first task for the plot_button_Callback is to read the input values. This involves:
Reading the current values in the three edit text boxes using the handles structure
to access the edit text handles.
Converting the two frequency values (f1 and f2) from strings to doubles using
str2double.
Evaluating the time string using eval to produce a vector t, which the callback used
to evaluate the mathematical expression.
The following code shows how the plot_button_Callback obtains the input:
% Get user input
f1 = str2double(get(handles.f1_input,'String'));
f2 = str2double(get(handles.f2_input,'String'));
t = eval(get(handles.t_input,'String'));
Calculate Data
After constructing the string input parameters to numeric form and assigning
them to local variables, the next step is to calculate data for the two graphs. The
plot_button_Callback computes the time domain data using an expression of sines:
x = sin(2*pi*f1*t) + sin(2*pi*f2*t);
The callback computes the frequency domain data as the Fourier transform of the time
domain data:
y = fft(x,512);
For an explanation of this computation, see the fft function.
Przeglądanie stron 272
1 2 ... 268 269 270 271 272 273 274 275 276 277 278 ... 499 500

Komentarze do niniejszej Instrukcji

Brak uwag