MATLAB Answers

reshaping tables and calculating combination of differences between variables

16 views (last 30 days)
ektor
ektor on 22 May 2012
Commented: Ory on 12 Oct 2016
Hi all,
I would like to reshape the following table
Area time rates
A1 2008 13
A1 2009 12
A2 2008 11
A2 2009 9
A3 2008 7
A3 2009 13
A4 2008 6
A4 2009 7
A5 2008 9
A5 2009 5
to this one
Time A1 Aa2 A3 A4 A5
2008 13 11 7 6 9
2009 12 9 13 7 8
and then extend the table with the following colums
time DA12 DA13 DA14 DA15 DA23 DA24 DA25 DA34 DA35 DA45
2008
2009
Where DA12=difference between area 1 and area 2. Similarly for the rest. Is it possible to write a code that will calculate all the combinations of the differences between these areas "quickly"because i have 50 such areas across a long period of time.
thanks in advance

  3 Comments

Jan
Jan on 22 May 2012
The question is not clear. What does "table" mean? An Excel table, UITABLE, a cell or a formatted text file? What is the "area 1" required for "DA12"? What are the "combinations" and ehat means "quickly" - in microseconds? What is a "long period of time"?
ektor
ektor on 22 May 2012
Thank you Simon.
The table is in an excel table and i want to convert it to the following form
Time A1 Aa2 A3 A4 A5
2008 13 11 7 6 9
2009 12 9 13 7 8
using matlab code, this is my first question. then i want to create additional colums, for example the column DA12 which is defined as follows
time DA12
2008 13-11 (the valu of A1 for the year 2008-the value of A2 for the year 8)
2009 12-9
So as you can see i want to calculate the difference of interest rates between areas for teach period ( 2008 and 2009.) and because I have many areas( in our example 5 areas) there are many combinations of such pair of areas. So, when i say "quickly'" i mean to be able to calculate all thesee pairs using matlab code. I hope to be more explicit this time
thank you again
Unless there is a completely different approach in obtaining these differences
Ory
Ory on 12 Oct 2016
I have the same question, as far as the 1st part is concerned: how do you pivot data in Matlab without using for loops? In R one can do it using the Reshape package for example, where one can 'melt' the dataset and 'cast' it into a new shape.

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by