Extract matching row from another cell array

2 visualizaciones (últimos 30 días)
Elysi Cochin
Elysi Cochin el 9 de Abr. de 2023
Comentada: dpb el 10 de Abr. de 2023
I have attached 2 mat-files named all_files.mat and full_details.mat
Each row in all_files.mat has a row as shown in image below
I wanted to separate it into 3 parts as shown in yellow, green and blue
I have written a code below to separate it into 3 parts into str1, str2 and str3
load all_files
for i = 1
temp = all_files{i};
kdash = strfind(temp,'_');
kdot = strfind(temp,'.');
str1 = temp(1:kdash(1)-1);
str2 = temp(kdash(1)+1:kdash(2)-1);
str3 = temp(kdash(2)+1:kdot(1)-1);
end
load full_details
Now I wanted to get the row from full details which satisfies the below condition,
str1 matches the string in column1_of_full_details &&
str2 matches column2_of_full_details &&
str3 matches column3_of_full_details &&
column7_of_full_details == 'English'
If does not exist go to the next row in all_details
There will be many rows satisfying this condition. So I would like to get the row with the longest description, that string in column8_of_full_details
and save the row from all_files and the description from full_details
For example, if
temp = 'mv89psg6zh4_33_46.avi';
After the satisfying the 4 conditions, my result would be (Please Note: The below output has more rows. For understanding I have displayed only 3 rows)
and then I would like to get the longest string from the last column and save it along with all_files in a new variable as
Please could someone help to to do the condition check with more than 1 condition and to find the longest string from a column
  1 comentario
dpb
dpb el 9 de Abr. de 2023
load https://www.mathworks.com/matlabcentral/answers/uploaded_files/1350039/all_files.mat
Error using load
Unable to read file 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1350039/all_files.mat'. If it is a Version 7 or earlier MAT-file, consider saving your data afresh in Version 7.3 MAT-files to access it from a remote location.

Iniciar sesión para comentar.

Respuesta aceptada

dpb
dpb el 9 de Abr. de 2023
Air code; the load operation didn't work online...
>> load all_files
>> pieces=split(extractBefore(all_files,'.'),'_');
Error using split (line 99)
Element 14 of the text contains 3 delimiters while the previous elements have 2. All elements must contain the same number of delimiters.
>> all_files(12:15)
ans =
4×1 cell array
{'-Ms9tsWmhyU_80_95.avi' }
{'-YI0cxuNcq8_262_272.avi'}
{'-_aaMGK6GGw_57_61.avi' }
{'-_hbPLsZvvo_172_179.avi'}
>>
on local machine.
You've got inconsistently defined data in the all_files file -- whassup w/ that? Is the leading underscore actually in the other data file to match or do the filenames have to be cleaned up first?
>> all_files=strrep(all_files,'-_','-');
>> pieces=split(extractBefore(all_files,'.'),'_');
Error using split (line 99)
Element 36 of the text contains 3 delimiters while the previous elements have 2. All elements must contain the same number of delimiters.
>> all_files(34:38)
ans =
5×1 cell array
{'-s4-6QTT7HE_235_241.avi'}
{'-t-ZWaJeH-o_0_15.avi' }
{'-uT_1VDvXok_8_15.avi' }
{'-vKO3uSG6Do_3_14.avi' }
{'-vg3vR86fu0_1_6.avi' }
>>
Well, now you've got even more underscores buried inside the filenames.
This isn't going to work as you've described at all; your file-naming convention isn't consistent.
  2 comentarios
Elysi Cochin
Elysi Cochin el 10 de Abr. de 2023
It is a downloaded dataset. They have named it so. I think we need to do a if condition to get it correctly, if there are only 2 underscores so and so and if there are 3 underscores. Else I too think it wont work. I saw only maximum 3 underscores (each name has 2 or 3 underscores)
dpb
dpb el 10 de Abr. de 2023
But so far you don't have a unique definition of what is a field delimiter and what is data with which to know what to do for all cases.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by