How to solve the problem of finding several similar names?

1 view (last 30 days)
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=[];

Accepted Answer

Walter Roberson
Walter Roberson on 26 May 2023
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

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!