필터 지우기
필터 지우기

How to make a grid periodic

조회 수: 1 (최근 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