How to match a matrix of features with a bunch of .mat files?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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?
0 comentarios
Respuesta aceptada
Voss
el 8 de En. de 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)
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre File Operations en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!