![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/576697/image.png)
How to make a grid periodic
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
DGM
am 8 Apr. 2021
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/576697/image.png)
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')
0 Kommentare
Siehe auch
Kategorien
Mehr zu Graphics Performance finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!