subtract elements in a matrix

For questions regarding the import, export and manipulation of data in EViews, including graphing and basic statistics.

Moderators: EViews Gareth, EViews Jason, EViews Steve, EViews Moderator

vytama
Posts: 58
Joined: Wed Dec 19, 2012 11:05 am

subtract elements in a matrix

Postby vytama » Thu Sep 27, 2018 10:16 am

Hi, I have a matrix(!i,!j) and for each !i(column) I would like to create another matrix with a row lag (!j-(!j-1)). How can I achieve that? Thank you.

EViews Matt
EViews Developer
Posts: 312
Joined: Thu Apr 25, 2013 7:48 pm

Re: subtract elements in a matrix

Postby EViews Matt » Thu Sep 27, 2018 10:50 am

Hello,

I don't yet understand what you're asking for. If the following was your initial matrix, what should the result to be?

Code: Select all

[  1  2  3 ]
[  4  6  8 ]
[ 10 15 20 ]

vytama
Posts: 58
Joined: Wed Dec 19, 2012 11:05 am

Re: subtract elements in a matrix

Postby vytama » Thu Sep 27, 2018 10:55 am

the new result should be a difference between rows:
[1-0=1 2-0=2 3-0=3]
[4-1=3 6-2=4 8-3=5]
[10-4=6 15-6=9 20-8=12]

the result after changes:

[1 2 3]
[3 4 5]
[6 9 12]

EViews Matt
EViews Developer
Posts: 312
Joined: Thu Apr 25, 2013 7:48 pm

Re: subtract elements in a matrix

Postby EViews Matt » Thu Sep 27, 2018 12:04 pm

I understand now, after the first row you want the row differences. For an initial matrix m, you can use something like the following:

Code: Select all

matrix result = m - @vcat(@filledvector(m.@cols, 0), @subextract(m, 1, 1, m.@rows - 1))

vytama
Posts: 58
Joined: Wed Dec 19, 2012 11:05 am

Re: subtract elements in a matrix

Postby vytama » Thu Sep 27, 2018 12:06 pm

thank you.


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 5 guests