plot multiple vertical line on the same graph

14 views (last 30 days)
Hello every one,
i would like to add many vertical lines in my gaph. The x-values where to draw them are stored in a table (index values [129x1). I have also tried to use (1x129) without success. I'am trying to call this coordinates but I am failing. I have tried to manually insert fake coordinates using several approaches and, as long I am not calling the coordinates from an array, everything works perfectly. Any idea how to deal with it?
see the code for more info.
in the attachments, you will find the graph where I would like to insert my vertical dotted lines.
%pefect like that, I just need to add chan33 for trigger or use lc variable
%as a map
figure(2)
Y = new_ch(:, 1:32).';
Y = Y ./ max(abs(Y), [], 1); % Divide by maximum value. Then all values are between -1 and 1
Y = Y + (1:32).';
plot(1:width(Y), Y);
hold on
set(gca,'xlim', [0 20000]) %set x-axis window diplayed
%xline(lc_swap) --> attempt n1 (fail)
%where lc swap is the table where
% for i = 1:length(lc_swap) --> attempt n2 (fail)
% xline(lc_swap(i));
% end
  2 Comments
VBBV
VBBV on 31 Oct 2022
Moved: VBBV on 29 Apr 2023
Y = rand(100,32);
Y = Y ./ max(abs(Y), [], 1); % Divide by maximum value. Then all values are between -1 and 1
Y = Y + (1:100).'
Y = 100×32
1.8983 1.8837 1.9839 2.0000 1.0098 1.7360 1.1801 1.3718 1.4069 1.8684 1.3255 1.2908 1.9853 1.3826 1.7236 1.0271 1.8422 1.8681 1.2277 1.4559 1.4744 1.7490 1.4421 1.4500 1.2726 1.3209 1.3340 1.3236 1.9594 1.5951 2.9865 2.3622 2.1162 2.0312 2.9454 2.0879 2.8811 2.6539 2.6109 2.9563 2.1052 2.6280 2.8326 2.3614 2.7638 2.3382 2.2446 2.0714 2.8476 2.5829 2.1851 2.3481 2.4826 2.8528 2.0125 2.7646 2.6111 2.1047 2.6500 2.5741 3.3653 3.3986 3.8464 3.0138 3.0631 3.9478 3.2846 3.9436 3.5100 3.0018 3.6986 3.0698 3.4120 3.3964 3.5260 3.0126 3.4691 3.5635 3.9408 3.4770 3.2626 3.8035 3.6930 3.6944 3.2413 3.1728 3.9217 3.7800 3.2870 3.1955 4.1957 4.4426 4.0594 4.3814 4.3730 4.3839 4.7455 4.8942 4.2216 4.3053 4.7783 4.2190 4.0126 4.4918 4.6701 4.8009 4.8656 4.5799 4.8127 4.5093 4.3324 4.9214 4.5301 4.4962 4.9444 4.6337 4.2959 4.1080 4.5738 4.8852 5.2752 5.3879 5.5717 5.8918 5.3334 5.7403 5.3227 5.4372 5.7051 5.2826 5.5151 5.1211 5.8758 5.4031 5.5052 5.2054 5.1055 6.0000 5.8554 5.5630 5.7075 5.6875 5.5154 5.5353 5.8798 5.5211 5.6635 5.5547 5.2098 5.9435 6.1826 6.6587 6.4039 6.2284 6.1775 6.8095 6.9194 6.3285 6.6069 6.0141 6.5987 6.6218 6.6246 6.3770 6.9606 6.9152 6.2205 6.5004 6.9088 6.9465 6.3319 6.1529 6.7850 6.4404 6.4424 6.5682 6.9526 6.6261 6.2351 6.4938 7.8992 7.7927 7.6291 7.2000 7.5529 7.5066 7.1737 7.4737 8.0000 7.6798 7.8385 7.8232 7.7653 7.8016 7.9455 7.7492 7.2452 7.6624 7.7268 7.6641 7.2928 7.1058 7.5501 7.2902 7.9790 7.7934 7.1645 7.5750 7.5673 7.3419 8.5981 8.3713 8.6999 8.4015 8.7897 8.7865 8.0562 8.6093 8.0362 8.0192 8.1172 8.1101 8.5405 8.5203 8.4207 8.8638 8.8983 8.0834 8.9501 8.3065 8.9461 8.3404 8.8765 8.3415 8.2667 8.9676 8.6536 8.2606 8.9556 8.4829 10.0000 9.2619 9.5650 9.1303 9.7168 9.8578 9.8362 9.8918 9.6944 9.5408 9.2990 9.8189 9.1325 9.3711 9.7777 9.0110 9.5800 9.7343 9.1092 9.0771 9.7775 9.6742 9.4879 9.4334 9.0516 9.7304 9.0952 9.1655 9.2000 9.1635 10.1201 10.7704 10.8281 10.6240 10.5874 10.7580 10.8195 10.1859 10.2453 10.5094 10.4190 10.7223 10.2835 10.5231 10.4952 10.6867 10.0192 10.6195 10.4733 10.8970 10.1816 10.4565 10.2763 10.5828 10.9557 10.2930 10.5549 10.4333 10.8054 10.0560
plot(1:32, Y);
idx = 1:10;
values = linspace(1,32,10);
xline(values(idx),'--')
VBBV
VBBV on 31 Oct 2022
Moved: VBBV on 29 Apr 2023
idx = 1:10; % index values
values = linspace(1,32,10); % x vector
xline(values(idx),'--')
pass the vector with its index values

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 31 Oct 2022
You can pass a vector to xline(). That would be for the case where you want the line to extend vertically from edge to edge.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!