Filter löschen
Filter löschen

Extract matching row from another cell array

1 Ansicht (letzte 30 Tage)
Elysi Cochin
Elysi Cochin am 9 Apr. 2023
Kommentiert: dpb am 10 Apr. 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 Kommentar
dpb
dpb am 9 Apr. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

dpb
dpb am 9 Apr. 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 Kommentare
Elysi Cochin
Elysi Cochin am 10 Apr. 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 am 10 Apr. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by