Cant show plot on a graph matlab GUI

19 次查看(过去 30 天)
Kenneth
Kenneth 2024-11-18,14:38
回答: Walter Roberson 2024-11-18,17:54
the plot for the graph dont appear when i input the values
%Reading Value for selected signal Converter
selectedFunction = app.DropDown.Value;
Fs = 1000; % Sampling frequency (Hz)
T = 1/Fs; % Sampling period (seconds)
L = 1000; % Length of signal (number of samples)
t = (0:L-1)*T; % Time vector
%Reading input parameter
f1 = str2double(app.Frequency1EditField.Value);
f2 = str2double(app.Frequency2EditField.Value);
%Initialize Signal
x = [];
%Selecting function
switch selectedFunction
case "Fourier"
x = sin(2*pi*f1*t) + sin(2*pi*f2*t);
% Add noise if the checkbox is selected (i.e., checked)
if app.WhiteNoiseRemoverCheckBox.Value
x = x + 0.5 * randn(size(t)); % Add noise when checkbox is checked
end
y = fft(x);
% Compute the two-sided spectrum
P2 = abs(y/L); % Magnitude of the FFT divided by the length
P1 = P2(1:L/2+1); % Single-sided spectrum (positive frequencies)
P1(2:end-1) = 2*P1(2:end-1); % Adjust for the single-sided spectrum
% Define the frequency axis
f = Fs*(0:(L/2))/L;
plot(app.UIAxes, t, x);
plot(app.UIAxes_2, f, P1);

回答(1 个)

Walter Roberson
Walter Roberson 2024-11-18,17:54
selectedFunction = app.DropDown.Value;
That is going to reply with a character vector even if the Items was initialized with a string array. uidropdown() converts string arrays into cell array of character vectors.

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by