How can I draw multiple vertical lines in math lab?
Ältere Kommentare anzeigen
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]
Antworten (1)
Star Strider
am 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 Kommentare
Muna Gutub
am 21 Feb. 2018
Star Strider
am 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.
Kategorien
Mehr zu Line Plots finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!