help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re:


From: James Sherman Jr.
Subject: Re:
Date: Thu, 22 Oct 2015 12:34:59 -0400


On Thu, Oct 22, 2015 at 12:06 PM, Jonathan Camilleri <address@hidden> wrote:
I downloaded Octave, and, I am trying to use it to create a machine learning algorithm e.g. K-nn.

Just before I start with this, hoping you provide me with some samples, I am trying to use printf command but the command window seems to be frozen.

Inline images 1

Inline images 2

Something wrong here?

See online tutorial at http://www.gnu.org/software/octave/doc/interpreter/, look for the section where Comma Separated Lists can be used, this is what I am trying to do.

--
Jonathan Camilleri

Mobile (MT): ++356 7982 7113
E-mail: address@hidden
Please consider your environmental responsibility before printing this e-mail.
 
I usually reply to emails within 2 business days.  If it's urgent, give me a call.

and, angel start-up investment opportunities available at http://slyth3.wix.com/jon-business.
Online resume is available online at http://mt.linkedin.com/in/jonathancamilleri and shared bookmarks at https://delicious.com/jon80.





_______________________________________________
Help-octave mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/help-octave


In regards to the printf error, note that the error is about that they need to be strings.  The cell array you've defined is comprised of numbers.  I believe this is what you want:

>> c =  = {"1", "2", "3", "4", "5"};
>> printf("%s ", c{:});
1 2 3 4 5 >>

The reason that Octave doesn't yell and scream at you (i.e. give an error) when you do:
>> c =  = {1, 2, 3, 4, 5};
>> printf("%s ", c{:});
☺ ☻ ♥ ♦ ♣ >>

Is that Octave doesn't really differentiate between a string and a number, it just the encoding for the character '1' is not the number 1 but 49 (its ascii value). You can even see this when in Octave if you try and add a number to a string:
>> a = '1'
a = 1
>> a+0
ans =  49

Furthermore, you seem to have a misunderstanding about what a comma separated list means/does, for example:
>> c =  = {"1", "2", "3", "4", "5"};
>> printf("%s ", c{:});
These two lines are equivalent to the single line:
>> printf("%s ", "1", "2", "3", "4", "5");

Or when you did:
>> c =  = {1, 2, 3, 4, 5};
>> printf(c{:});
is equivalent to
>> printf(1, 2, 3, 4, 5);
which is why you got an error, because printf requires the format string as its first argument.  You can type
>> help printf
to see further documentation about printf

Further, when you did:
>> c = {1, 2, 3, 4, 5};
>> average(c)
you're not using a comma separated list here, so you're passing the cell array c into your function average.  However, you seem to not have a function called average in your path, so it couldn't find a function called average, so that is why you got an error you got.

Finally (and this may just be me), but screenshots are terribly annoying to work with (for example, I can't copy and paste lines that you used into an octave command window), so I'd recommend putting commands inline in your email, like what I've done above.

Hope this helps,

James Sherman Jr.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]