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

1 visualizzazione (ultimi 30 giorni)
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?

Risposta accettata

Voss
Voss il 8 Gen 2024
% 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

Più risposte (0)

Categorie

Scopri di più su File Operations in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by