Search code examples
matlabfile-iomatlab-load

How to load data in MATLAB from current script folder?


There is a script myScript.m, under D:\myProjects, so its location is D:\myProjects\myScript.m

I want to load a .dat file at D:\myProjects\myData\someData.dat

How do I use the load() function without using the absolute path like

data = load('D:\myProjects\myData\someData.dat')   % something I do not want

Solution

  • data = load('myData\someData.dat')   
    

    Use a relative path. This assumes you are executing the program from it's home directory D:\myProjects.

    If you need to call the script from different folders you should pass the path to the .dat as an argument to the script.