[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: What is wrong here?
From: |
Geraint Paul Bevan |
Subject: |
Re: What is wrong here? |
Date: |
Tue, 9 Nov 2004 21:41:07 +0000 (GMT) |
On Tue, 9 Nov 2004, Vic Norton wrote:
> octave> for i = invIndices(1:3)
> > printf ("%3u: %s\n", i, dates(i, :));
> > endfor
> 234: warning: implicit conversion from matrix to string
> ???
> 218: 102545---MSSaeeypp---222000000000
>
> What is wrong with using the column vector invIndices(1:3) as an
> index set? Why does it foul up the date array?
The problem is that the entire column is assigned to the loop variable on
the first pass:
# column vector
octave> a = [1;2;3];
octave> for i = a; disp ( "i: "); disp ( i ); endfor
i:
1
2
3
This is consistent with what you get when you loop over a matrix
octave> a = [1,2,3;4,5,6;7,8,9];
octave> for i = a; disp ( "i: "); disp ( i ); endfor
i:
1
4
7
i:
2
5
8
i:
3
6
9
This means, however, that the entire array is being passed to the printf
function - hence the error message. Therefore you will need to transpose
your invIndices vector so that it is a row vector when looped over.
--
Geraint Bevan
http://homepage.ntlworld.com/geraint.bevan
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------