Plot matrices in area graph of unequal length (i.e. size of rows)

4 Ansichten (letzte 30 Tage)
Hi all,
I am having two matrices, the one is 50x2 and the other is 20x2. The first columns of both are dates, and the second colums are payments per each date. I would simply like to display the data in an area graph where the 50x2 matrix would be on the botom (i.e. the red), and the 20x2 matrix would be on the top (i.e. the yellow). Obviously the sum of both vectors would be the total height of the graph.
However to peform such a task, as I perceive it, I would have to make the two vectors compatible dimensionwise (i.e. have the same number of rows).
My thinking is to try to 'reshape' the matrices such as any idetical numbers on the first colum become removed, and numbers of the second column that remain, are stacked as more colums, with the gaps filled by either zero on nan.
Here is an example, 'cause it can be hard to understand:
X_init = [7.3743 0.0383 ;
7.3743 0.0379;
7.3743 0.0377;
7.3743 0.0378;
7.3743 0.0374;
7.3743 0.0273;
7.3742 0.0272;
7.3742 0.0272;
7.3742 0.0270;
7.3742 0.0270] ; % Initial matrix
X_resh = [7.3743 0.0383 0.0379 0.0377 0.0378 0.0374 0.0273 ;
7.3742 0.0272 0.0270 0.0270 NaN NaN NaN] ; % Reshaped Matrix
Thus far I am not certain that the above might lead to the desired result.
Thanks for your help in advance
KR,
KMT.

Akzeptierte Antwort

Star Strider
Star Strider am 5 Jan. 2019
The only approach I can suggest is to interpolate one or both data sets to a common set of dates. This is best done using the retime (link) function. This first requires that you create your data as a timetable (see the documentation section on Create Timetables (link) to understand how to do that).
  2 Kommentare
Konstantinos Tsitsilonis
Konstantinos Tsitsilonis am 5 Jan. 2019
Thanks for your useful input! A couple of hours later I managed to solve my problem using the functions you pointed out.
Star Strider
Star Strider am 5 Jan. 2019
As always, my pleasure!
The newer time functions are extremely useful.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by