[Top][All Lists]

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

Re: How to call a function that is in another file?

From: Emil M. Oanta
Subject: Re: How to call a function that is in another file?
Date: Tue, 24 Dec 2019 10:00:00 +0000 (UTC)

Hello Farzad,

From your message I understand that there are several questions.

To read automatically a csv file is possible, but it takes a lot of effort to read all the system information and to decide if the 'separator' is a comma (which is used in some cases as decimal point). Then the program should deduce what symbol is used as a field separator. I use the principle 'keep it simple' and I usually write many comment lines in my codes in order to remember after months or years what was the logic of that given context. So, in the code I sent you, the input csv file should use this convention:
- first line may be or may be not the field separator definition, i.e. 'sep=;'
- if this line is missing, then the default separator is comma.

As a basic principle, I initialize the data in my codes, so the compile/interpreter should know what to do with that variables. So it would be fine to initialize the array/matrix.

Be aware that in GNU Octave you may start the indexes of the lines/columns from 1, but in the API C++ codes they should start from 0.



On Monday, December 23, 2019, 11:37:07 PM GMT+2, Farzad Torabi <address@hidden> wrote:

Hello dear Emil

I am coming back to this question for some updates and maybe resolve one small problem. for me , there is only one small problem in reading that Octave always reads the first cell 1,1 as NaN.

so in my code at the moment, after reading I just write data(1,1)= a , in which a is any number that should actually be read for the cell 1,1 .

added to that, is there any possibility to make this code in a way to read any csv file with any separator without the need from the user to intervene and change the separator type in case of error ?

On Mon, Nov 18, 2019 at 5:54 AM Emil M. Oanta <address@hidden> wrote:
The first line in the text csv file must be 'sep=;' or 'sep=,'.
This line defines the separator to be considered in the read function...
Attached you may find a csv starting with 'sep=;'.
Of course, using 'search'/'replace all' you may change ';' to ',' or vice versa.
The command is:

On Sunday, November 17, 2019, 3:52:55 PM GMT+2, Farzad Torabi <address@hidden> wrote:

Thank you very much Emil

I did 

test=load_csv('test.csv' ,  "," )

but it didn't work , shall you please help me with the syntax I need to use ?

On Wed, Nov 13, 2019 at 6:36 PM Emil M. Oanta <address@hidden> wrote:
A computer code line in GNU Octave ends with either ';' semicolumn or nothing.
Semicolumn means that the result is not displayed.

I learnt that csv may be correctly read in Excel if the first line in the TEXT csv file specifies the symbol use to separate the values.
For 'comma' it is 'sep=,', but this is the default separator.
For 'semicolumn' it is 'sep=;', which is used when the decimal point is actually a comma, ','.

I send you my code which loads a csv file in a double type matrix which is returned to the upper level.
I use this original code in a set of upper level codes, please see figure 3 in

You may modify it to return a matrix of strings, which may be processed in the upper level.


On Wednesday, November 13, 2019, 3:12:14 PM GMT+2, Farzad Torabi <address@hidden> wrote:

well I think I have some problems that start with reading from input .csv files , but I have them also when I input them manually instead of reading from csv. first I noted the ; semicolon is causing problem to read a row and put it in a matrix (list ) like test1= [1, 100, 200, 300] 

if I try to change the semicolon to comma then I get the error:

error: load: unable to determine file format of 'test.csv'

but then even when I input the test matrix manually and then ran the function that included this data as input: 

result =  myfunc(input1,input2, test1]

error: 'result' undefined near line 1 column 1

So I don't know whether I am not using the function calling correctly, or it's a formatting problem or what ...

On Wed, Nov 13, 2019 at 11:06 AM Emil M. Oanta <address@hidden> wrote:

Try to trace the execution by printing some messages from the files/functions.
If you place a message in an if (echo > 0) ... you can activate and deactivate messages using 'echo'.
If the line is finished by ; there are no answers regarding the result of that line of the program.


On Tuesday, November 12, 2019, 5:33:08 PM GMT+2, Doug Stewart <address@hidden> wrote:

On Tue, Nov 12, 2019 at 10:09 AM Farzad Torabi <address@hidden> wrote:
Hi All

I have several files in a folder that each of them is a function and each one should call the other file. 
there is no constructed , so I need to call the main function from command prompt , but when I type the function name with its inputs, I don't get any output since it seems like first the function mfile should be loaded. How do I do that ?

SeyedFarzad Torabi
Master of Mech. Eng.
Politecnico Di Milano

If you don't get an error message then the function was run.
Perhaps the function does not display any data?
DASCertificate for 206392

SeyedFarzad Torabi
Master of Mech. Eng.
Politecnico Di Milano

SeyedFarzad Torabi
Master of Mech. Eng.
Politecnico Di Milano

SeyedFarzad Torabi
Master of Mech. Eng.
Politecnico Di Milano

reply via email to

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