How can I draw multiple vertical lines in math lab?
10 views (last 30 days)
Show older comments
How can I draw multiple vertical lines in math lab? I want the distance between them 2 and y start from y=1 to y=20 and the x-axis [1:20]
0 Comments
Answers (1)
Star Strider
on 21 Feb 2018
Try this:
figure(1)
plot([1:2:20; 1:2:20], [20*ones(1,10); ones(1,10)], '-r')
Change the color and line-type to create the vertical lines you want.
2 Comments
Star Strider
on 21 Feb 2018
This will work for that, and for any other values of the parameters you choose:
X_min = 1; % Initial ‘X’ Value
X_max = 20; % Maximum ‘X’ Value
X_step = 1; % Step ‘X’ Value
Lv = numel(X_min:X_step:X_max); % X-Vector Length
Y_min = 1; % Minimum Value For Y-Lines
Y_max = 20; % Maximum Value For Y-Lines
figure(1)
plot([X_min:X_step:X_max; X_min:X_step:X_max], [Y_max*ones(1,Lv); Y_min*ones(1,Lv)], '--r')
You will still need to define the color and line-type (here a red dashed line, defined by '--r'). See the documentation for plot for those options.
See Also
Categories
Find more on 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!