Octave adding path of folder and subfolder

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Octave adding path of folder and subfolder

usman

I have several .m inside a folder(and subfolders) that defines its self  as
a PROGRAM . However, these functions are in another directory of the main
folder (or these functions are in sub-directories). I am not sure which
commands may I include to perform this task without any errors.

I tried using addpath(), load(), etc. but I don't know the proper usage, may
be that's a reason.

Maincode.m (Is a file in directory e.g /program/example/maincode.m):

% start of code
plot_traction_force(t_cycle,F_trac_veh);
%end of code

plot_traction_force.m (Is a file in directory e.g
/program/plotfunctions/plot_traction_force.m):

% start of code
function [] = plot_traction_force(t_cycle,F_trac_veh)
% code goes here
end
%end of code

The directory view:

|-->EVD_Program
 |-->example
    |--> maincode.m
 |-->Functions
    |-->plotfunctions
          |--> plotftn1.m
          |--> plotftn2.m
 |-->extension
    |-->vehicle_data.m  
    |-->electric_machine_map.m

where plotftn1.m, vehicle_data.m, electric_machine_map.m are functions
called by maincode.m.

I don't know how to implement this for a number of functions that might be
in different directories of the parent directory.

QUESTION is " How do I include a command or a method that can do the same
operation like in MATLAB you just select include folder and subfolders and
everything works fine... how can I do this in OCTAVE??
<http://octave.1599824.n4.nabble.com/file/t373187/2019-02-04.png>




--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Octave adding path of folder and subfolder

Mike Miller-4
On Mon, Feb 04, 2019 at 14:36:59 -0600, usman wrote:

> The directory view:
>
> |-->EVD_Program
>  |-->example
>     |--> maincode.m
>  |-->Functions
>     |-->plotfunctions
>           |--> plotftn1.m
>           |--> plotftn2.m
>  |-->extension
>     |-->vehicle_data.m  
>     |-->electric_machine_map.m
>
> where plotftn1.m, vehicle_data.m, electric_machine_map.m are functions
> called by maincode.m.
>
> I don't know how to implement this for a number of functions that might be
> in different directories of the parent directory.
>
> QUESTION is " How do I include a command or a method that can do the same
> operation like in MATLAB you just select include folder and subfolders and
> everything works fine... how can I do this in OCTAVE??
I think you are looking for the function "genpath".

Calling

    addpath (genpath ('/path/to/EVD_Program'))

will add EVD_Program and each subdirectory to the load path.

--
mike



signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Octave adding path of folder and subfolder

apjanke-floss


On 2/4/19 4:12 PM, Mike Miller wrote:

> On Mon, Feb 04, 2019 at 14:36:59 -0600, usman wrote:
>> The directory view:
>>
>> |-->EVD_Program
>>   |-->example
>>      |--> maincode.m
>>   |-->Functions
>>      |-->plotfunctions
>>            |--> plotftn1.m
>>            |--> plotftn2.m
>>   |-->extension
>>      |-->vehicle_data.m
>>      |-->electric_machine_map.m
>>
>> where plotftn1.m, vehicle_data.m, electric_machine_map.m are functions
>> called by maincode.m.
>>
>> I don't know how to implement this for a number of functions that might be
>> in different directories of the parent directory.
>>
>> QUESTION is " How do I include a command or a method that can do the same
>> operation like in MATLAB you just select include folder and subfolders and
>> everything works fine... how can I do this in OCTAVE??
>
> I think you are looking for the function "genpath".
>
> Calling
>
>      addpath (genpath ('/path/to/EVD_Program'))
>
> will add EVD_Program and each subdirectory to the load path.
>
>

I stand corrected. I didn't know about genpath. Forget what I said about
enumerating all your directories yourself in init_EVD_Program. Use
genpath instead.

Cheers,
Andrew


Reply | Threaded
Open this post in threaded view
|

Re: Octave adding path of folder and subfolder

usman