How to make a grid periodic

4 visualizaciones (últimos 30 días)
sawasawa
sawasawa el 7 de Abr. de 2021
Respondida: DGM el 8 de Abr. de 2021
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.

Respuestas (1)

DGM
DGM el 8 de Abr. de 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)
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')

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by