check if the destination file is the same as what I want
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi!
I have a folder inside which there are multiple .mat files. I want to perform an operation such that I get the plots of only 2 specific .mat files. For example,
The path that contains the .mat files are -- 'C:\ParentFolder\Folder\Subfolder\*.mat'
Now I want to perform an operation like -- *.mat == a.mat.
All this will be done in a for loop as I have to do this step for many files (in different folders).
How do I proceed?
댓글 수: 0
답변 (2개)
Florian Bidaud
2023년 6월 21일
편집: Florian Bidaud
2023년 6월 21일
Like
if isfile(a.mat)
my_file = a.mat
end
If you want to put all your files in an array:
file_name_array = {'file1' 'file2' 'file3'};
path = 'C:\folder'
for i = 1:length(file_name_array)
if isfile(fullfile(path,file_name_array{1}))
files.(file_name_array{1}) = load(fullfile(path,file_name_array{1}));
else
disp([file_name_array ' does not exist'])
end
end
댓글 수: 0
Mayur
2023년 6월 21일
Hi Indrani!
You can use the dir function to get a list of all .mat files in the specified folder, and then loop over this list to load and plot the data from the desired files.
folder = 'C:\ParentFolder\Folder\Subfolder\';
fileList = dir(fullfile(folder, '*.mat'));
for i = 1:length(fileList)
filename = fileList(i).name;
if strcmp(filename, 'a.mat') || strcmp(filename, 'b.mat')
data = load(fullfile(folder, filename));
% Remaining code
end
end
You can read more about dir and fullfile from the following documentations:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!