How to match a matrix of features with a bunch of .mat files?

조회 수: 1 (최근 30일)
Atefeh
Atefeh 2024년 1월 8일
댓글: Voss 2024년 1월 9일
Hello friends
I have a matrix of features and this file is one of the files of the feature.zip files which is renamed.
I want to match this file with the .mat files of the feature folder, and the code give me the name of file for example gives me the full name of output_a_LLG_fault_bus3_feature
can you advise?

채택된 답변

Voss
Voss 2024년 1월 8일
% unzip the zip file
unzip('feature.zip')
% get info about the mat files anywhere under the feature directory:
files = dir(fullfile('.','feature','**','*.mat'));
% construct those mat file full path names:
fn = fullfile({files.folder},{files.name});
% load the new feature vector, to match against:
S = load('new_feature_vector.mat');
% matching_mat_name will contain the name of the mat file whose feature_vector
% variable matches that of S (initially there is no match found):
matching_mat_name = '<No match>';
% loop over the mat files:
for ii = 1:numel(files)
% load the mat file:
data = load(fn{ii});
% check whether there is a variable called 'feature_vector' in this mat
% file and whether it is the same as the one from new_feature_vector.mat:
if isfield(data,'feature_vector') && ...
isequal(data.feature_vector,S.feature_vector)
% if it exists and matches, store the mat file name:
matching_mat_name = fn{ii};
% found a match, so stop looking:
break
end
end
% display the matching mat file name:
disp(matching_mat_name)
/users/mss.system.uIMUZf/feature/LL_G/output_a_LLG_fault_bus3_feature.mat

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by