Cant show plot on a graph matlab GUI

19 Ansichten (letzte 30 Tage)
Kenneth
Kenneth am 18 Nov. 2024 um 14:38
Beantwortet: Walter Roberson am 18 Nov. 2024 um 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);

Antworten (1)

Walter Roberson
Walter Roberson am 18 Nov. 2024 um 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.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by