How i check to see that the function returns x and y data set in a 0 to 1 second time interal
1 view (last 30 days)
Show older comments
Firstly how do i turn the following script into a function?
t=0:0.01:10
ac= inputdlg('Enter a value for the amplitude');
a= str2double(ac);
f=0.5;
y= a*sin(2*pi*f*t)
plot(t,y);
axis([-10 10 -10 10]);
title('Sine Function');
xlabel('Time axis');
ylabel('Amplitude axis')
Secondly how do i check to see that it returns the x and y dataset in a 0 to 1 second time interval?
Many thanks
0 Comments
Answers (1)
Utkarsh Belwal
on 31 Aug 2020
Hi,
In MATLAB, syntax for defining function is as follows:
function [y1,…,yN] = myfun(x1,..,xM)
% function code
end
y1,…,yN are the N outputs of the function and x1,…,xM are the M inputs to the function. Also make sure that the function and script name is same. Refer to the documentation for more information: https://www.mathworks.com/help/matlab/ref/function.html#d120e397526
To get the t and y between 0 and 1 you can define t as,
t = 0:0.01:1;
DISCLAIMER: These are my own views and in no way depict those of MathWorks
10 Comments
Rik
on 31 Aug 2020
What do you have in your file exactly? Before the 'function' and after the 'end' you should not have anything in that file. You also put in the .m after the function name where you call it. That is not needed.
I would seriously consider doing a less basic Matlab tutorial than you have done. Mathworks provides the Onramp course for free. That should give you a better idea of how to use Matlab. This forum is not very well suited to show you the basics of how a function works.
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!