How to plot a graph with y-axis values that can be incremental?

8 visualizaciones (últimos 30 días)
I was trying to figure out on how to plot the graph where y-axis values would be increase.
Starting code:
T_start1 = {182 444 392 201 155}; %start time (x-axis)
T_end = {728 938 674 638 702}; %end time (x-axis)
figure;
xdata = [cell2mat(T_start1); cell2mat(T_end)];
nT = size(xdata,2);
ydata = [1:nT; 1:nT; NaN(1,nT)];
xdata(end+1,:) = NaN;
plot(xdata(:),ydata(:),'.-r','LineWidth',2,'MarkerSize',8);
My intention is to get this kind of graph (blue line). Is this possible?
Current code:
T_start1 = {182 444 392 201 155}; %start time (x-axis)
T_end = {728 938 674 638 702}; %end time (x-axis)
P_array = {15 15 6 6 15}; %y-axis
figure;
xdata = [cell2mat(T_start1); cell2mat(T_end)];
nT = size(xdata,2);
ydata = [cell2mat(P_array); cell2mat(P_array); NaN(1,nT)];
xdata(end+1,:) = NaN;
plot(xdata(:),ydata(:),'.-r','LineWidth',2,'MarkerSize',8);
However, the output that I obtained wasn't the expected graph I want it to look like. Any help appreciated. Thanks in advance!

Respuesta aceptada

the cyclist
the cyclist el 23 de Abr. de 2022
In order to get a plot that looks like the blue line, you would need y data that gradually increases, levels off, then decreases. But, your y data has only two values: 6 and 15. That is why you only get two levels.
If you plot larger markers, you can see a bit more clearly the actual data being plotted:
T_start1 = {182 444 392 201 155}; %start time (x-axis)
T_end = {728 938 674 638 702}; %end time (x-axis)
P_array = {15 15 6 6 15}; %y-axis
figure;
xdata = [cell2mat(T_start1); cell2mat(T_end)];
nT = size(xdata,2);
ydata = [cell2mat(P_array); cell2mat(P_array); NaN(1,nT)];
xdata(end+1,:) = NaN;
plot(xdata(:),ydata(:),'.-r','LineWidth',2,'MarkerSize',32);
  3 comentarios
Marc Daniel
Marc Daniel el 23 de Abr. de 2022
Editada: Marc Daniel el 23 de Abr. de 2022
Oh I see, I understand what you meant. Thanks for the explanation. ^
I was wondering if we can do this by just using value of 15 and 6.
P_array becomes [15,30,36,42,57]
But we are still using value of 15 and 6.
Is this possible?
Speaking of the cell array, yeah you are right. I should have just use numeric vectors since I'm only dealing with numbers.
Marc Daniel
Marc Daniel el 24 de Abr. de 2022
Editada: Marc Daniel el 24 de Abr. de 2022
I thought of a way of incrementing P_array.
P1 = [cumsum(P_array)];
P2 = [cumsum(P_array, 'reverse')];
P1(end+1) = P2;
The code seems to have error for P1(end+1) = P2 but I couldn't understand why it shows error.
Error comment: Unable to perform assignment because the left and right sides have a different number of elements.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by