Plotting multiple vertical lines with a for loop

조회 수: 10 (최근 30일)
Cian McAuley
Cian McAuley 2020년 10월 21일
댓글: Cian McAuley 2020년 10월 21일
I need to plot vertical lines on a graph at points defined from an array imported from an excel file.
Samples = xlsread('ProjectData.xlsx','Sampling Strategy','A6:B44');
SampleDepth = Samples(:,2);
for i = 1:SampleDepth
xline(i);
end
SampleDepth is a 29x1 double. I need it to plot a vertical line (hence using xline) for each depth specified. I thought that using a for Loop like this would therefore plot a vertical line at each specified point, but Matlab returns:
Error using xline (line 29)
Must pass in a value.
Error in IsotopeGraphs (line 24)
xline()
What needs to be done to fix this? Can xline even be used like this or does it not work?
  댓글 수: 2
KSSV
KSSV 2020년 10월 21일
You cannot draw a line with single point..you need to have two points...read the documentation.
what is xline by the way?
Cian McAuley
Cian McAuley 2020년 10월 21일
You do not need two points to draw a line if you use the function xline() or yline(), which will draw a straight line perpendicular to that axis at the specified point.

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

답변 (3개)

Ameer Hamza
Ameer Hamza 2020년 10월 21일
You seem to have a function named xline() which is shadowing the built-in function xline(). Check the output of
which xline
and if it is not something like
.../toolbox/matlab/specgraph/xline.m
then change its name to something else.

Chenguang Yan
Chenguang Yan 2020년 10월 21일
Try this
sz = size(SampleDepth,1);
for i = 1:sz
xline(SampleDepth(i));
end

Andy
Andy 2020년 10월 21일
SampleDepth is a matrix so cannot be used to generate the for loop.
I think you meant to use the length of SampleDepth
for i = 1:length(SampleDepth)

카테고리

Help CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by