How to make this plot
Ältere Kommentare anzeigen
Hello everyone, thanks in advance for your time and help! I'm going to expose my situation:
I've got a logical matrix, of dimensions, let's say, (P,T). For istance:
P=4;
T=3;
M=[1 1 0 0 ;1 1 1 0; 1 0 0 0];
I should make a plot on the plan of axis T (x-axis) and P (y-axis), as it follows. For each fixed T, i should obtain a vertical bar which stands from P=1 to P=4. This bar should be a two-tone bar: it should be composed of a red-colour part, as extended as the number of values 1 occurring in the correspondant column of the matrix M. The remaining segment should be green, as extended as the number of values 0 occurring in the correspondant column of the matrix.
For istance, fixed T=1, i should get a red line from P=1 to P=2 and a green line for the remaining values of P; fixed T=2, i should have a red line from P=1 to P=3 and a green part for P=4, and so on.
Substantially, i need to repeat this for each T ( i fix the column of the matrix and plot P-values for that column) and put all the vertical lines in the same plot ( should i use hold on ?). The red lines' length should be equal to the number of 1 values occurring in the columns. The green lines' length should be equal to the number of 0-values (remaining values) occurring in the columns.
I've been trying a lot, but can't get which should be the right plot function to be used. Thank You for helping me!
3 Kommentare
Stephen23
am 11 Jun. 2018
In two lines:
>> image(rot90(M),'CDataMapping','scaled')
>> colormap([0,1,0;1,0,0])

Stefano Di Vito
am 11 Jun. 2018
Stephen23
am 12 Jun. 2018
"is there a way to get this image with the borders of each bar"
Not really. You could with a lot of fiddling around, but it would not be worth it. That is why I put this as a comment, not an answer: it is mostly for interest.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Discrete Data Plots finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

