How to switch to this graph? Mathematical question

Hi, I have a bit complicated question about a way to obtain a graph from a set of data.
I have a code that return a solution of three variables, related to solving a system of several equations.
For example, Matlab output is like the following:
a = [1 0.2 0.2];
b = [0 0.4 0.4];
c = [0 0.4 0.4]; which are plotted on distance x = [0 0.5 1];
a, b, c represent three volume fractions, with the constraint that sum over a column is 1 (on the left of the figure).
However, for an easier understanding, I need a graphic representation showing not the absolute values of those fractions, but their distribution (on the right).
I know it's likely a "mathematical question" than "Matlab question", but I don't know how to proceed.
I need an appliable strategy on any solution, not this one in particular.
Thanks for your help!!

 Accepted Answer

Try this —
x = [0 0.5 1];
a = [1 0.2 0.2];
b = [0 0.4 0.4];
c = [0 0.4 0.4];
figure
patch([x flip(x)], [c zeros(size(c))], 'g', 'FaceAlpha',0.75)
hold on
patch([x flip(x)], [b ones(size(a))], 'r', 'FaceAlpha',0.75)
patch([x flip(x)], [b flip(a+c)], 'b', 'FaceAlpha',0.75)
hold off
text([1 1 1]*0.8, [0.2 0.5 0.8], compose('%c',['c','a','b']), 'FontWeight','bold')
.

4 Comments

Yes, this is absolutely correct, there's only one problem.
This code can be coupled only to this easy example. Actually, solution can be very complex, also with 50 points for every variable. The example I considered is very easy, with only three points and regular lines.
My question is not about that problem, I asked for a single code which can be applied to every case.
I hope you understand me.
Is it possible?
A more robust approach would be to use the area function, creating the matrix by vertically concatenating the vectors in the order in which they are to be plotted, and then transposing the resulting matrix (noting that the area function plots across the columns, not the rows as in most other graphics functions so that the plotted lines correspond to the ‘CalculateYcoordinates’ matrix) —
x = [0 0.5 1];
a = [1 0.2 0.2];
b = [0 0.4 0.4];
c = [0 0.4 0.4];
abc = [c; a; b]' % Note The Concatenation Order & Subsequent Transposition
abc = 3×3
0 1.0000 0 0.4000 0.2000 0.4000 0.4000 0.2000 0.4000
CalculateYcoordinates = cumsum(abc,2) % Information Only To Demonstrate What The 'area' Funciton Plots, Not Required For The Code
CalculateYcoordinates = 3×3
0 1.0000 1.0000 0.4000 0.6000 1.0000 0.4000 0.6000 1.0000
figure
area(x, abc)
text([1 1 1]*0.8, [0.2 0.5 0.8], compose('%c',['c','a','b']), 'FontWeight','bold')
That approach should work for similar problems with different [c,a,b] vectors and ‘abc’ matrices.
.
Yes, this is exactly what I need! It works for any vectors, and the display order is optional.
Thank you!!
As always, my pleasure!
.

Sign in to comment.

More Answers (1)

Try:
plot(x,c,x,1-b)

1 Comment

This is correct, there's only one problem.
This can be coupled only to this easy example. Actually, solution can be very complex, also with 50 points for every variable. The example I considered is very easy, with only three points and regular lines.
My question is not about that problem, I asked for a single code which can be applied to every case.
I hope you understand me.

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!