How i check to see that the function returns x and y data set in a 0 to 1 second time interal
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Utkarsh Belwal
2020-8-31
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 个评论
Rik
2020-8-31
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!