I have a file located in /path/to/Matlab/myData.mat. The path /path/to/Matlab has been in the search path. I launch Matlab from /path/to/Matlab/workspace/.
However, the command if (exist('myData.mat','file')==2) delete('myData.mat'); returns error saying that File myData.mat cannot be found.
There is only one file named myData.mat among all the search paths. Is it mandatory to use absolute or relative path when call the delete() function providing the location has been added to the search path?
My OS is Ubuntu 16, and Matlab v2015b.
Use which to find the full path
Related
In my code I want to indicate paths to files that are independent on which computer the code is run. In other words, I want the script to operate only in the folder where it is located because my friend's computer can have different drive names, folders' names etc. The task is to load files by indicating where they are located. I thought this would work: "load("..\Folder\file.mat")". However, Matlab gives an error
Error using load
'..\Folder\file.mat' is not found in the current folder or on the MATLAB path, but exists in:
D:\D (synced)\Folder 3\Matlab
D:\D (synced)\Folder 3\Data
Change the MATLAB current folder or add its folder to the MATLAB path.
I checked and file.mat is in Folder which is located in the same directory as the script that I run.
Could someone tell how to make all paths independent on what computer they are run and avoid the error?
I suppose that both your script and file are in the folder Folder.
To make it operating system independent, you could use mfilename to retrieve the path of your script, and use fullfile to concatenate the path with the file name.
p = mfilename( 'fullpath');
file = load( fullfile( p, 'file.mat'));
So I've got the following init.vim under ~/.config/nvim/
source plugins.vim
plugins.vim lives in the same directory.
When I'm opening [Neo]Vim I always get
Error detected while processing /home/luke/.config/nvim/init.vim:
line 1:
E484: Can't open file plugins.vim
Does anybody know what I am missing?
The path for source command is always taken relative of the current working directory. Hence, you should specify full path instead. For example,
source <sfile>:h/plugins.vim
Another possibility is using runtime command that does searching along the 'runtimepath'. E.g.
runtime plugins.vim
I am trying to load a folder path on mac to a folder of MATLAB data sets.
This is the code I am using:
folder_path = '/Documents/2020/Root Locus/Data';
files = dir(fullfile(folder_path,'*.mat'))
The file I am running the code from is located in the root locus folder. My files variable keeps appearing empty as nothing has loaded to it, any help?
You need to write the path as either the relative path from Matlab's current folder or the absolute path for the system. An absolute path will start with / and specify the location from the topmost system directory. Relative paths do not start with /.
If you are running Matlab from Root Locus, then try folder_path = 'Data';
The absolute path makes the code more portable, so also try folder_path = '/Users/<username>/Documents/2020/Root Locus/Data';
I'm trying to set up the search path of my laptop matlab. I saw "." in my office computer matlab(set up by someone else).
What does . mean?
How can I add . also as my search path. I tried to add it but it failed.
There are two methods for specifying paths: absolute and relative paths.
An absolute path is e.g. C:\some\folder in Windows, or e.g./Some/folder in Linux and Mac. As the name says, these are absolute and always the same. Relative paths however are paths specified in relation to the current working directory.
When creating relative paths, . is the current working directory. .. similarly is the parent directory. This can be used to add subfolders to the path, e.g. ./subfolder or add another directory which in located in the parent directory, e.g. ../other_directory.
Afaik, you don't need to add the current working directory to the search path, as this is the default behavior of MATLAB.
I want to add a file say abc.m in matlab default search path without modifying its path.
So I put the file in one of the folders of my default search path. But still matlab doesn't recognizes when I type the file name on the terminal. Any suggestions.
Here is the folder in which I put my file C:\Program Files\MATLAB\R2011a\toolbox\local
Here are the contents of abc.m
restoredefaultpath;
clear all;
clc;
I am not looking for answers like edit startup.m and use addpath to add the file path .
I got my error.
I forgot to restart the matlab instance so that it could index the files in its default search path