How to make a grid periodic

2 次查看(过去 30 天)
sawasawa
sawasawa 2021-4-7
回答: DGM 2021-4-8
I have the code below to plot grid lines for the y values
clear all; close all; clc;
y =[-0.906 -0.120 0.664 1.450 2.235 3.021 3.806 4.591 5.377];
for i=1:length(y)
plot(0:1:10, y(i)+(0:1:10).*0,'m');
hold on
end
I want to make it repeat at least twice above and below with a period 2*pi . Any help on how to achieve this will be greatly appreciated.

回答(1 个)

DGM
DGM 2021-4-8
Do you actually need plot lines, or are you trying to make the plot gridlines have a particular spacing?
If the latter, consider the example:
y=linspace(0,6*pi,100);
x=sin(y);
plot(x,y); grid on
yl=get(gca,'ylim');
set(gca,'ytick',(yl(1):pi/4:yl(2))-0.906)
Of course, that -0.906 offset obfuscates that the spacing is a nice pi/4
On the other hand, if you really just want a bunch of lines plotted, you can do that too.
clf
% pick how far you want the lines to extend in x and y
x=[1 10];
yl=[-2*pi 2*pi];
% calculate the array
y=repmat((yl(1):pi/4:yl(2))'-0.906,[1 2]);
plot(x,y,'b')

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by