How do I make line stacked graph like this?

9 views (last 30 days)
Hello,
I have a question regrading this graph.
I just made this graph in the EXCEL that x axis is angle(0 to 90 degree) and time(sec).
However, it is very time-cusming process, because, I have to assign single time into a single series like in the graph.
So, I want to make like this graph in the MATLAB.
It's actually stacking x=const lines in time.
When I put starting angle and ending angle in all time, I want to plot line stacked graph like in the above.
How do I make it?
Thanks,
Hyojae.

Accepted Answer

Karim
Karim on 30 Dec 2022
Edited: Karim on 1 Jan 2023
Hi, its much easier if you would provide the numerical data as numerical data and not a screenshot ;)
Anyhow, yes such a plot can be made quite simple in matlab. First let's type over your data
data = [ 80 20;
80 30;
100 10;
100 30;
120 20;
120 40;
140 30;
140 50;
160 40;
160 70];
One way to achieve this is by using a for loop. Note that it is also possible with a single call to the plot command by introducing nan in between the line's:
figure
hold on
for i = 1:2:size(data,1)
plot(data(i:i+1,2),data(i:i+1,1),'-o','LineWidth',1.5)
end
xlim([0 80])
ylim([0 180])
hold off
grid on
  1 Comment
HyoJae Lee
HyoJae Lee on 1 Jan 2023
Highly appreciated, Karim.
It helps me a lot!

Sign in to comment.

More Answers (1)

Voss
Voss on 1 Jan 2023
Edited: Voss on 1 Jan 2023
Here's how you can do it with one plot call creating multiple lines:
data = [ ...
80 20;
80 30;
100 10;
100 30;
120 20;
120 40;
140 30;
140 50;
160 40;
160 70];
x = reshape(data(:,2),2,[]);
y = reshape(data(:,1),2,[]);
plot(x,y,'-o')
xlim([0 80])
ylim([0 180])
grid on

Categories

Find more on Line Plots 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!