How can I draw multiple vertical lines in math lab?
Afficher commentaires plus anciens
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]
Réponses (1)
Star Strider
le 21 Fév 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 commentaires
Muna Gutub
le 21 Fév 2018
Star Strider
le 21 Fév 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.
Catégories
En savoir plus sur Line Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!