1
In the following MATLAB plot, I want to draw x-axis and y-axis, both through origin. What would be the easiest code?
x = linspace(-2*pi,2*pi,100);
y1 = sin(x);
y2 = cos(x);
figure
plot(x,y1,x,y2)
1
In the following MATLAB plot, I want to draw x-axis and y-axis, both through origin. What would be the easiest code?
x = linspace(-2*pi,2*pi,100);
y1 = sin(x);
y2 = cos(x);
figure
plot(x,y1,x,y2)
3
I am not familiar with Matlab, but using the Python Matplotlib, I can give you the following hint:
a) set xlim to [-6.4, 6.4] and ylim to [-1.1, 1.1]
b) draw horizontal through origin: draw an arrow from [-6.4, 0] to [6.4, 0]
c) vertical axis through origin: draw an arrow from [0, -1.1] to [0, 1.1]
The code can be written easily, according to Matlab syntax.
1
Matlab contains properties (since R2015b) to control this.
Append your code with the following:
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';