Plot function not working correctly - Non-continuous graphing

6 Ansichten (letzte 30 Tage)
Frank Katz
Frank Katz am 17 Okt. 2020
Kommentiert: Ameer Hamza am 17 Okt. 2020
Hello,
I am trying to graph the following data but the plot function is not connecting the points in a continuous manner.
Find below two graphs. The first is when I try to plot the two arrays and the second is when I scatter them. As you can see from the second graph, I wish to connect these points with a continuous line. However as you can see from the first graph, when I use plot it creates a mess.
Does anyone have any suggestions?
Code:
xta = [2.1 0.3 0.8 1.7 1.6 2 2.4 2.2 0.4 3 1.2 0.7 0.2 0 2.5 0.9 0.5 2.6 2.8];
h6_ta = [5.97853697427416 -2.80975652924937 -4.80049651251653 3.64650224735648 3.10258743393927 5.16551230747825 10.8859845706138 7.13859238208390 -4.01961018236456 30.0721681625590 -0.578609482801659 -5.26354831338203 -1.45940663189310 0.154573905982674 13.5744223560721 -3.99608140671335 -4.88444411593052 16.7730149487159 24.0494440428712];
subplot(2,1,1);
plot(xta,h6_ta)
title 'Figure 1'
subplot(2,1,2);
scatter(xta,h6_ta,'o')
title 'Figure 2'
Figure:
Thank you

Antworten (1)

Ameer Hamza
Ameer Hamza am 17 Okt. 2020
The array xta is not sorted. Try the following code
xta = [2.1 0.3 0.8 1.7 1.6 2 2.4 2.2 0.4 3 1.2 0.7 0.2 0 2.5 0.9 0.5 2.6 2.8];
h6_ta = [5.97853697427416 -2.80975652924937 -4.80049651251653 3.64650224735648 3.10258743393927 5.16551230747825 10.8859845706138 7.13859238208390 -4.01961018236456 30.0721681625590 -0.578609482801659 -5.26354831338203 -1.45940663189310 0.154573905982674 13.5744223560721 -3.99608140671335 -4.88444411593052 16.7730149487159 24.0494440428712];
subplot(2,1,1);
[xta_sorted, idx] = sort(xta);
plot(xta_sorted,h6_ta(idx))
title 'Figure 1'
subplot(2,1,2);
scatter(xta,h6_ta,'o')
title 'Figure 2'

Kategorien

Mehr zu Discrete Data Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by