Plotting multiple vertical lines with a for loop
9 views (last 30 days)
Show older comments
Commented: Cian McAuley on 21 Oct 2020
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
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)
What needs to be done to fix this? Can xline even be used like this or does it not work?
Ameer Hamza on 21 Oct 2020
You seem to have a function named xline() which is shadowing the built-in function xline(). Check the output of
and if it is not something like
then change its name to something else.
Chenguang Yan on 21 Oct 2020
sz = size(SampleDepth,1);
for i = 1:sz
Andy on 21 Oct 2020
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)
Find more on Labels and Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!