Why am I getting a 'parse error' at t and how do I fix it?
4 次查看(过去 30 天)
显示 更早的评论
I am trying to write a program that returns the gaussian distribution given input arguments of a vector times t and a value of RMS deviation tau.
This is my code, but it keeps saying there is a parse error at line 14: "Parse error at t: usage might be invalid MATLAB syntax"
% Write a program that returns the Gaussian distribution given input
% arguments of a vector of times t and a value of a root mean squared (RMS)
% deviation tau
function gaussian_distribution = generate_gaussian(t, tau)
% t: Vector of times
% tau: RMS deviation
% Calculate the Gaussian distribution
gaussian_distribution = exp(-t.^2 / (2 * tau^2)) / (tau * sqrt(2 * pi));
end
% Example usage and plot
t = linspace(-5, 5, 1000); % Example time vector
tau = 1.5; % Example RMS deviation
% Generate Gaussian distribution
gaussian_dist = generate_gaussian(t, tau);
% Plot the Gaussian distribution
figure;
plot(t, gaussian_dist, 'LineWidth', 2);
title('Gaussian Distribution');
xlabel('Time');
ylabel('Amplitude');
grid on;
0 个评论
采纳的回答
Voss
2024-1-29
编辑:Voss
2024-1-29
Function definitions in a script must be at the end of the script, like this:
% Example usage and plot
t = linspace(-5, 5, 1000); % Example time vector
tau = 1.5; % Example RMS deviation
% Generate Gaussian distribution
gaussian_dist = generate_gaussian(t, tau);
% Plot the Gaussian distribution
figure;
plot(t, gaussian_dist, 'LineWidth', 2);
title('Gaussian Distribution');
xlabel('Time');
ylabel('Amplitude');
grid on;
% Write a program that returns the Gaussian distribution given input
% arguments of a vector of times t and a value of a root mean squared (RMS)
% deviation tau
function gaussian_distribution = generate_gaussian(t, tau)
% t: Vector of times
% tau: RMS deviation
% Calculate the Gaussian distribution
gaussian_distribution = exp(-t.^2 / (2 * tau^2)) / (tau * sqrt(2 * pi));
end
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!