How can I load my data from a variable filename
85 views (last 30 days)
Show older comments
mohammad
on 29 Jul 2015
Commented: Shahzanani Senin
on 5 Sep 2020
Hello, How can I load 80 files(.mat) from folder each has a number ex: file_1, file_2, file_3 ...file_80. What I did the following:
for x= 1:80
load ('file_x.mat')
But it's not working: gave me the following error: Error using load Unable to read file 'file_x.mat': no such file or directory.
0 Comments
Accepted Answer
Sebastian Castro
on 29 Jul 2015
You need to do this by converting the numerical value of "x" to a string and concatenating that with the rest of the file name string. For example:
for x= 1:80
load (['file_' num2str(x) '.mat'])
end
- Sebastian
5 Comments
Steven Lord
on 19 Jun 2020
Are those the only files with that pattern of name in your directory?
D = dir('file_000*');
for k = 1:numel(D)
fprintf('Processing file %s.\n', D(k).name)
end
Shahzanani Senin
on 5 Sep 2020
I have the question also because I have the same problem to load the data. I have 248 files with different name which is 94 files of ADmaskMean_AD_1 until ADmaskMean_AD_94, and 154 files of ADmaskMean_NORMAL_1 until ADmaskMean_NORMAL_154. How can I do that? Thank you!
More Answers (0)
See Also
Categories
Find more on Search Path in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!