Search code examples
linuxmatlabsaving-data

Command to save files in MATLAB on Linux OS


My situation here is that I need to send my program to my university's cluster which runs on Linux. To save file on my com locally using Windows, I simply use

fid = fopen('exp.txt', 'w');
fprintf(fid, '%6.2f %12.8f\n', y);
fclose(fid);

What is the Linux equivalent of this command if I want to save to a directory on the cluster for example /home/MyFolder/filename.txt? Do I use

mkdir('/home/MyFolder/')

Furthermore how do I specify a directory in Linux? I have no experience using Linux at all.


Solution

  • If you just start MatLab while you're in your desired directory (cd /path/to/dir/ to change current directory), your existing code will still work.

    If you need a different working directory (e.g. to find scripts and other data files), fopen('/path/to/exp.txt', 'w'); should help.