Greetings, in this tutorial we will move on drawing advanced schemes, plots on Octave. To do that we must first remember our previous lectures and know the usage of some important functions. To have an intuitionyou may check the previous lectures about Octave.
Below are the some important functions that we are going to use in our drawings,
plot: In two dimension plot(X,Y) returns the points of Y versus the representing X values.
hold: Command to add multiple plots in one figure
figure: Generates a new figure window where the user may add plots below later.
contour: contour(Z) draws
Our first task is to draw a house like shape in Octave. To do that first we defined a set of points (matrix) which will our lines pass and intersect.
X = [-6 -6 -7 0 7 6 6 -3 -3 0 0 ; -7 2 1 8 1 2 -7 -7 -2 -2 -7 ];
This will generate a X matrix having 2 rows and 11 columns. Then we defined a new figure with the command
figure
Later a for loop was written to connect sets in X matrix and form a shape as follows,
plot( X( 1, (i:i+1) ) , X( 2, (i:i+1)) );
hold on;
end
After writing the code our graph will look like this,
X = [-6 -6 -7 0 7 6 6 -3 -3 0 0 ; -7 2 1 8 1 2 -7 -7 -2 -2 -7 ];
figure;
for i=1:size(X,2)-1
plot( X( 1, (i:i+1) ) , X( 2, (i:i+1)) );
hold on;
end
As you can see we only need to connect right bottom place of the shape to gather a house. To do that below code was written
plot( X( 1, [11 1] ) , X( 2, [11 1] ) );
And in overall code and our house will look like this,
X = [-6 -6 -7 0 7 6 6 -3 -3 0 0 ; -7 2 1 8 1 2 -7 -7 -2 -2 -7 ];
figure;
for i=1:size(X,2)-1
plot( X( 1, (i:i+1) ) , X( 2, (i:i+1)) );
hold on;
end
plot( X( 1, [11 1] ) , X( 2, [11 1] ) );
Moreover, after doing this we may now form another shape by writing simple for loop,
first define the top point,
x0=8;
y0=14;
Then limit the plot in positive x,y axes and limit them upto 16 as follows,
xlim([0 16]);
ylim([0 16]);
And form the top of the tree with the below for loop,
%top of the tree
for i=1:7
for j=0:i-1
text(x0-j,y0-i,int2str(j+1)) ;
text(x0+j,y0-i,int2str(j+1)) ;
end
end
Then the bottom two lines of the tree,
%bottom of the tree
for i=8:9
text(x0,y0-i,int2str(1)) ;
end
And little text,
text(x0-2,y0-11,'Happy New Year') ;
The overall code and shape will look like this,
figure;
x0=8;
y0=14;
xlim([0 16]);
ylim([0 16]);
%top of the tree
for i=1:7
for j=0:i-1
text(x0-j,y0-i,int2str(j+1)) ;
text(x0+j,y0-i,int2str(j+1)) ;
end
end
%bottom of the tree
for i=8:9
text(x0,y0-i,int2str(1)) ;
end
%text
text(x0-5,y0-11,'Happy New Year!','Color','green','FontSize',34)
For scalable version you may change the text into title and obtain the below scheme,
title('Happy New Year!','Color','green','FontSize',34)
And to use the subplot function we may do accomplish another task to see the behaviour of sin function and its powers, Below code will plot the square, third, fourth, fifth, sixth, seventh, eight, nineth, tenth, ninety ninth and hundredth powers of sin function
x=0:pi/100:4*pi;
y1=sin(x);
y2=sin(x).^2;
y3=sin(x).^3;
y4=sin(x).^4;
y5=sin(x).^5;
y6=sin(x).^6;
y7=sin(x).^7;
y8=sin(x).^8;
y9=sin(x).^9;
y10=sin(x).^10;
y99=sin(x).^99;
y100=sin(x).^100;
subplot(4,4,1); plot(y1); title('y1')
subplot(4,4,2); plot(y2); title('y2')
subplot(4,4,3); plot(y3); title('y3')
subplot(4,4,4); plot(y4); title('y4')
subplot(4,4,5); plot(y5); title('y5')
subplot(4,4,6); plot(y6); title('y6')
subplot(4,4,7); plot(y7); title('y7')
subplot(4,4,8); plot(y8); title('y8')
subplot(4,4,9); plot(y9); title('y9')
subplot(4,4,10); plot(y10); title('y10')
subplot(4,4,11); plot(y99); title('y99')
subplot(4,4,12); plot(y100); title('y100')
In our following lectures we will focus on advanced 3D drawing with octave.
With your support,
Octave Github repository
@wodsuz ©
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey @wodsuz I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit