Hi,
jwe asked me udse the help
list....
I hope this is the help
list...
Please see the text below.
Thanks
jma
Please use the help list.
jwe
On 5-Dec-2006,
Jorgen Andersson wrote:
| Hi John,
|
| How would I do what
was intended:
|
| 2 4
| 3 8
| 9 3
|
| I want to
index with [2,3,4] and then [3,4,5] ... [4,5,6] by letting
| i index the
index range matrix. Can you do it with octave.
| My octave script works if in
a loop. The loop is some slow
| so that is why I would like to use an index
to the index ranges.
Please see below for: i , a , b.
|
| Thanks for your
reply
|
| Best...
| jma
|
|
________________________________
|
| From: John W. Eaton [mailto:address@hidden]
| Sent:
Mon 12/4/2006 4:48 PM
| To: Jorgen Andersson
| Cc: address@hidden
|
Subject: FW: Matrix index, Please e-mail back.
|
|
|
| On
4-Dec-2006, Jorgen Andersson wrote:
|
| | The Version is 2.1.73 Running on
win XP with no command-line sw.
| |
| |
________________________________
| |
| | From: Jorgen Andersson
| |
Sent: Mon 12/4/2006 11:24 AM
| | To: address@hidden
| | Subject: Matrix
index, Please e-mail back.
| |
| |
| | Hi,
| |
| | I'm not sure,
but depending on how indexing should work this could be a bug...
| |
| |
Note how the second row in b = [3,5] , used as index numbers into "a"
| | the
second column ought to be [4,8,3] not [3,4,8] as last on this page.
|
|
| | It looks like octave makes note of the first index and uses it and not
[3,5]
| |
| | If this is not a bug and I do not want to use loops, how can
I make the
| | index work as I planned it?
| |
| | Best...
| |
Jorgen Andersson
| |
| | octave:300> i
| | i =
| |
1 2
| | octave:301> b
| | b =
| | 2 4
|
| 3 5
| | octave:302> a
| | a =
| |
1 2 3 4 5
| | 2 3 4
5 6
| | 3 4 5 6 7
|
| 9 8 7 6 5
| | 0
3 4 5 6
| | octave:303> a(b(i,1):b(i,2),i)
| | ans
=
| | 2 3
| | 3 4
| |
9 8
|
| This is not a bug.
|
| octave:1> i =
[1, 2]
| i =
|
| 1
2
|
| octave:2> b = [2, 4; 3, 5]
| b
=
|
| 2 4
|
3 5
|
| octave:3> b(i,1)
| ans
=
|
| 2
|
3
|
| octave:4> b(i,2)
| ans
=
|
| 4
|
5
|
| octave:5> b(i,1):b(i,2)
| ans
=
|
| 2 3 4
|
| This happens
because when you make a range using matrix values, only
| the first element
of the matrix values are used. In other words, if
| M1 and M2 are
matrices, then the range _expression_ M1:M2 is equivalent
| to
M1(1):M2(2). Octave has this "feature" for compatibility with
|
Matlab.
|
| Finally, you are indexing the array A with
|
|
a([2,3,4], [1,2])
|
| and it looks like Octave gave you the right result
for that operation.
|
| jwe
|
|
| <META
HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
| <HTML>
|
<HEAD>
|
| <META NAME="Generator" CONTENT="MS Exchange Server
version 6.5.7638.1">
| <TITLE>FW: Matrix index, Please e-mail
back.</TITLE>
| </HEAD>
| <BODY>
| <DIV
id=idOWAReplyText17110 dir=ltr>
| <DIV dir=ltr><FONT face=Arial
color=#000000 size=2>Hi John,</FONT></DIV>
| <DIV
dir=ltr><FONT face=Arial
size=2></FONT> </DIV>
| <DIV dir=ltr><FONT
face=Arial size=2>How would I do what was
|
intended:</FONT></DIV>
| <DIV dir=ltr><FONT face=Arial
size=2></FONT> </DIV>
| <DIV dir=ltr><FONT
face=Arial size=2>2 4</FONT></DIV>
| <DIV
dir=ltr><FONT face=Arial size=2>3 8 </FONT></DIV>
|
<DIV dir=ltr><FONT face=Arial size=2>9
3</FONT></DIV>
| <DIV dir=ltr><FONT face=Arial
size=2></FONT> </DIV>
| <DIV dir=ltr><FONT
face=Arial size=2>I want to index with [2,3,4] and then
| [3,4,5] ...
[4,5,6] by letting</FONT></DIV>
| <DIV dir=ltr><FONT
face=Arial size=2>i index the index range matrix. Can you do
| it with
octave.</FONT></DIV>
| <DIV dir=ltr><FONT face=Arial
size=2>My octave script works if in a loop. The
| loop is some
slow</FONT></DIV>
| <DIV dir=ltr><FONT face=Arial
size=2>so that is why I would like to use an index
| to the index
ranges.</FONT></DIV>
| <DIV dir=ltr><FONT face=Arial
size=2></FONT> </DIV>
| <DIV dir=ltr><FONT
face=Arial size=2>Thanks for your reply</FONT></DIV>
| <DIV
dir=ltr><FONT face=Arial
size=2></FONT> </DIV>
| <DIV dir=ltr><FONT
face=Arial size=2>Best...</FONT></DIV>
| <DIV
dir=ltr><FONT face=Arial
size=2> jma</FONT></DIV></DIV>
| <DIV
dir=ltr><BR>
| <HR tabIndex=-1>
| <FONT face=Tahoma
size=2><B>From:</B> John W. Eaton
| [mailto:address@hidden]<BR><B>Sent:</B>
Mon 12/4/2006 4:48
| PM<BR><B>To:</B> Jorgen
Andersson<BR><B>Cc:</B>
|
address@hidden<BR><B>Subject:</B> FW: Matrix index, Please
e-mail
| back.<BR></FONT><BR></DIV>
|
<DIV>
| <P><FONT size=2>On 4-Dec-2006, Jorgen
Andersson wrote:<BR><BR>| The
| Version is 2.1.73 Running on win
XP with no command-line sw.<BR>|<BR>|
|
________________________________<BR>|<BR>| From: Jorgen
Andersson<BR>| Sent: Mon
| 12/4/2006 11:24 AM<BR>| To:
address@hidden<BR>| Subject: Matrix index, Please
| e-mail
back.<BR>|<BR>|<BR>| Hi,<BR>| <BR>| I'm
not sure, but depending on
| how indexing should work this could be a
bug...<BR>| <BR>| Note how the
| second row in b = [3,5]
, used as index numbers into "a"<BR>| the second column
| ought to be
[4,8,3] not [3,4,8] as last on this
page.<BR>| <BR>| It
| looks like octave makes note of
the first index and uses it and not
| [3,5]<BR>| <BR>|
If this is not a bug and I do not want to use loops, how
| can I make
the<BR>| index work as I planned it?<BR>| <BR>|
|
Best...<BR>| Jorgen Andersson<BR>| <BR>|
octave:300> i<BR>| i
| =<BR>|
1 2<BR>| octave:301> b<BR>| b
=<BR>|
| 2
4<BR>| 3 5<BR>| octave:302>
a<BR>| a
| =<BR>| 1 2
3 4 5<BR>| 2
|
3 4 5 6<BR>| 3
4 5 6
| 7<BR>|
9 8 7 6 5<BR>|
0
| 3 4 5 6<BR>|
octave:303> a(b(i,1):b(i,2),i)<BR>| ans
|
=<BR>| 2 3<BR>|
3 4<BR>| 9
|
8<BR><BR>This is not a bug.<BR><BR>
octave:1> i = [1, 2]<BR> i
|
=<BR><BR> 1
2<BR><BR> octave:2> b = [2, 4; 3,
|
5]<BR> b =<BR><BR>
2 4<BR>
| 3
5<BR><BR> octave:3> b(i,1)<BR>
ans
| =<BR><BR>
2<BR> 3<BR><BR>
octave:4>
| b(i,2)<BR> ans
=<BR><BR>
4<BR>
| 5<BR><BR>
octave:5> b(i,1):b(i,2)<BR> ans
|
=<BR><BR> 2 3
4<BR><BR>This happens because when
| you make a range using
matrix values, only<BR>the first element of the matrix
| values are
used. In other words, if<BR>M1 and M2 are matrices, then
the
| range _expression_ M1:M2 is equivalent<BR>to M1(1):M2(2).
Octave has this
| "feature" for compatibility
with<BR>Matlab.<BR><BR>Finally, you are indexing the
|
array A with<BR><BR> a([2,3,4],
[1,2])<BR><BR>and it looks like Octave gave
| you the right
result for that
|
operation.<BR><BR>jwe<BR></FONT></P></DIV>
|
|
</BODY>
| </HTML>