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-(!j-1)). How can I achieve that? Thank you.
-
- EViews Developer
- Posts: 560
- 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:
[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]
[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 Developer
- Posts: 560
- 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 16 guests