
In my point of view, the code is simple and very useful for the beginner who just starting at matlab programming.
The above example is generating a sine wave using the matlab m-file.
below is the code,
function shili01
h0=figure('toolbar','none',...
'position',[198 56 350 300],...
'name','example1');
x=-pi:0.05:pi;
y=sin(x);
plot(x,y);
xlabel('X');
ylabel('Y');
title('SIN( )');
grid on
here is the explanation, the above code is runnable, just copy to m-file, save it, and run it.
function shili01 % this indicate the function's name is shili01
h0=figure('toolbar','none',... % figure is to open above window
'position',[198 56 350 300],...%position is the figure size [left, bottom, width, height]

%(195=left, 56=bottom, 350=width, 300 =height)
'name','example1');%giving the figure a name=example 1
x=-pi:0.05:pi; %x=-3.14159265, then adding -3.14159265+0.05, continue the adding until %x=3.14159265
y=sin(x);%mathematical function of sine
plot(x,y);%plotting the graph
xlabel('X');%labeling X the graph at x axis; you can change the name 'X' to anything you like
ylabel('Y');%labeling Y the graph at y axis; you can change the name 'Y' to anything you like
title('SIN( )');%title of the graph, that is SIN()
grid on%you can try change grid on to grid off to see the different
I also a beginner in matlab,
so please tell me if my explanation is wrong.
No comments:
Post a Comment