How to solve the problem of finding several similar names?

2 次查看(过去 30 天)
Hello friends, there are 2 problems in my code
1_ in the line "[row,column]=find(contains(filenamenew,string(filename)))" I am looking for the sample 9967, but the find command also finds other similar samples such as 49967 or 59967.
2=1- In the line "filenamenew{i}=(filename(:,1:end-7); " filenamenew is saved as a cell, I don't want this to happen
clc
clear
close all
cd training_data_out\
folderInfo = dir('**/*.wav');
cd ..\
addpath training_data_out\
load('ID.mat')
ID=trainingdataa(2:end,1);
ID=table2array(ID);
% working (current) folder
for i=1:length(folderInfo)
filename =folderInfo(i).name;
filenamenew{i}=(filename(:,1:end-7);
end
%BB=unique(id)
filename=[];
for id=1:length(ID)
filename =ID(id);
column=[];
[row,column]=find(contains(filenamenew,string(filename)));
total_im=[];

采纳的回答

Walter Roberson
Walter Roberson 2023-5-26
pat = digitboundary + filename + digitboundary;
[row,column]=find(contains(filenamenew, pat));
This constrains the search to cases where what is before and after the ID is something that is not a digit -- could be a beginning of string, could be a letter, could be a symbol such as '#" -- but not a digit. So ABC9967.mat could match but not ABC19967.mat or ABC99675.mat

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by