How to generate a number of parallel lines (x=constant)?

조회 수: 3 (최근 30일)
sha
sha 2015년 6월 3일
댓글: Star Strider 2015년 6월 3일
Hello, Could anyone tell me how to generate equally-spaced lines parallel to y-axis? Just like comb generation as shown in the attached file. I tried to generate using the following code, however, no success:
% code
lambda= [1.52:0.002222:1.58]; % x-axis
for m=722:749;
k[m]=2*3.8*150./m;
end
y=0:0.01:1;
plot(lambda*ones(size(y)), y, 'LineWidth', 1)
xlabel('\lambda (\mum)','FontSize',16);
ylabel('Y','FontSize',16);

채택된 답변

Star Strider
Star Strider 2015년 6월 3일
The code you posted is not MATLAB syntax.
This works:
x = 1:10;
figure(1)
plot([x; x], [zeros(1, length(x))*min(ylim); ones(1, length(x))*max(ylim)])
You will have to experiment with it to get the result you want.
  댓글 수: 2
sha
sha 2015년 6월 3일
Thanks, Could you tell me what plot([x; x] is doing here?
Star Strider
Star Strider 2015년 6월 3일
My pleasure.
It plots two matrices, one is is a (2xN) matrix of identical ‘x’ values in each row, where N is the length of ‘x’. (The second is a matrix of the same size, going from the minimum to maximum values of ylim in each column.)
MATLAB uses column-major indexing, so I’m taking advantage of that here. The plot function takes each column of ‘x’ and plots the corresponding column of ‘y’. The two rows in each column of ‘x’ are the same, and the two rows in each column of ‘y’ differ, plotting a vertical line for each column.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by