This question already has answers here:
What does two dots before a slash mean? (../) [closed]
(1 answer)
What do the dots mean in relative file path?
(5 answers)
What does a dot mean in a URL path?
(3 answers)
Closed 4 years ago.
I stumble across some MATLAB codes about data file paths, something like:
data=csvread(sprintf('../data/cdflevel%dtable.csv',cdflevels(i)));
I am not sure what '../' does. Anyone can explain it?
../ moves one folder up from the current directory, before then changing to the data directory in the parent folder. It's not specific to MATLAB, just a standard way of navigating a file system.
Related
This question already has answers here:
How to get all files under a specific directory in MATLAB?
(8 answers)
Closed 5 years ago.
I have this folders :
D:/ Houses/objects/*.jpg
D:/ Towers/objects/*.jpg
D:/ Hotels/objects/*.jpg
.
.
.
.
The first folder have different name but inside those folders exists a folder that have the same name (objects) that contain different images in .jpg that i already know how to get them all.
The problem is the first folders have different names , so how can i go over those folders to get the .jpg in matlab, when they have different names and the name donĀ“t have the same prefix either ?
Thank you very much
Use dir
files = dir('D:/*/objects/*.jpg');
fullPath = arrayfun(#(i) fullfile(files(i).folder, files(i).name), (1:length(files))', 'uni', 0);
This question already has an answer here:
How to Set Path in Matlab?
(1 answer)
Closed 7 years ago.
I have created my own mfile and would like to add it permanently lie built in functions so that I dont have to specify path. Is there a way to do it?
You should store your .m file (either script or function) in a folder belonging to the MatLab search path.
To add your own folder to the MatLab search path you can use eiterh:
the Set Path tool, available on the MatLab Home toolbar
use the buil-in function path (from the Command Window or, for example, as part of a script)
E. g.
path(path,'c:\my_folder\my_sub_folder')
Hope this helps.
Write your file and save it and then add the containing folder to the MATLAB search path. You do not need to look for it every time.
addpath('c:/matlab/myfiles')
Note: your filename should not exist within MATLAB, otherwise your file would be the default one, when you call that command.
You can also do most of the work from command-line:
First, create a folder,
mkdir('c:/matlab/myfiles')
Add it to the top of your search path,
addpath('c:/matlab/myfiles')
and then save the search path for future MATLAB sessions
savepath c:/matlab/myfiles/pathdef.m
This question already has answers here:
List all files in a directory given a regular expression / a set of extensions (Matlab)
(3 answers)
Matlab equivalent of `endsWith`: How to filter list of filenames regarding their extension?
(1 answer)
Closed 7 years ago.
I want to be able to detect a file by looking at its extension:
.m,
.fig,
.mdl,
.slx
but not
.mat
or others.
The final use will be to call DIR with a regular expression that filters out all the unnecessary files.
My first obstacle was to define a word of a single character "m". I couldn't figure out which expression should I use for REGEXP, and the documentation of Matlab was not clear enough.
An example of usage will be helpful, and a reference to a more understandable place will be very appreciated.
This question already has answers here:
Trying to download a zip file from a weblink with powershell
(1 answer)
PowerShell -WebClient DownloadFile Wildcards?
(3 answers)
Closed 9 years ago.
I am working on a script to download a series of files from a http location to a local directory. The filename consists of a time and date stamp as well as a static string. As far as I know, I have to have the exact filename when downloading using System.Net.Webclient, which is where I have an issue.
Is there either a wildcard method to use in System.Net.Webclient, or is there a way I can capture and parse the directory listing as it appears when I go to the parent directory in a browser?
The filenames are as such...
FLASH_20131112_203721_WEEKLYFY_C.dat.gz
The first numerical portion is a date, the second portion is a timestamp.
This question already has answers here:
How to get all files under a specific directory in MATLAB?
(8 answers)
Closed 8 years ago.
I have my data in multiple folders. Let's say I have a folder containing 100 subfolders at the moment that look like this:
/folder/Re0001/vitesse
/folder/Re0002/vitesse
/folder/Re000N/vitesse
/folder/Re000N+1/vitesse
/folder/Re0100/vitesse
I want to import the vitesse file into a cell array. This is the code that i am using at the moment:
numfiles=100;
mydata=cell(1,numfiles);
for i=1:numfiles
mydata{i}=uiimport;
end
It is a working solution.
However, if it involves 100 or more files I have to specify each folders and files manually, which is very troublesome.
By the way I am new to Matlab so can you please incorporate example code with the directory given.
I did something similar few days ago. Have a look at the matlab function ls. If you are using windows system, you are all set. If your are using linux, you may need to split the results. However newer version of matlab have the strsplit function that will do the job, or you will use regular expressions.
In your case,
list = ls('/folder/*/vitesse');
will give you a list of your files.