subtract elements in a matrix
Moderators: EViews Gareth, EViews Jason, EViews Steve, EViews Moderator
subtract elements in a matrix
Hi, I have a matrix(!i,!j) and for each !i(column) I would like to create another matrix with a row lag (!j(!j1)). How can I achieve that? Thank you.

 EViews Developer
 Posts: 290
 Joined: Thu Apr 25, 2013 7:48 pm
Re: subtract elements in a matrix
Hello,
I don't yet understand what you're asking for. If the following was your initial matrix, what should the result to be?
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 ]
Re: subtract elements in a matrix
the new result should be a difference between rows:
[10=1 20=2 30=3]
[41=3 62=4 83=5]
[104=6 156=9 208=12]
the result after changes:
[1 2 3]
[3 4 5]
[6 9 12]
[10=1 20=2 30=3]
[41=3 62=4 83=5]
[104=6 156=9 208=12]
the result after changes:
[1 2 3]
[3 4 5]
[6 9 12]

 EViews Developer
 Posts: 290
 Joined: Thu Apr 25, 2013 7:48 pm
Re: subtract elements in a matrix
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))
Who is online
Users browsing this forum: No registered users and 6 guests