How to make a grid periodic

3 ビュー (過去 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 Center および File Exchange2-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