Removing a character from a table (that's within a struct)
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Yonathan Zarkovian
am 7 Okt. 2021
Kommentiert: Yonathan Zarkovian
am 13 Okt. 2021
Hi,
I have a .mat file with the name faceDatasetGroundTruth.mat (a struct) that contains a table (called 'faceDataset') with two columns.
Each value in the second column starts and ends with a ' character, which I'd like to remove so that I'm only left with [95,71,226,313] in the first row, for example.
Thanks in advance.
1 Kommentar
C B
am 7 Okt. 2021
Bearbeitet: C B
am 8 Okt. 2021
Is there any specific reason for doing so ?
because when i run following it shows me that first char is '[' and not '''
>> faceDataset.face{1}(1)
ans =
'['
>> faceDataset
faceDataset =
3×2 table
filename face
________ ___________
'ab' '[1 2 2 4]'
'bc' '[1 2 2 4]'
'cd' '[1 2 2 4]'
>> faceDataset.face{1}
ans =
'[1 2 2 4]'
>> faceDataset.face{1}(1)
ans =
'['
>> faceDataset.face{1}(end)
ans =
']'
Akzeptierte Antwort
Stephen23
am 8 Okt. 2021
Bearbeitet: Stephen23
am 8 Okt. 2021
As far as I understand, you want to convert one column/variable of the table from cell array of character vectors to numeric. This is easy with convertvars:
S = load('faceDatasetGroundTruth.mat')
T = S.faceDataset
F = @(c)sscanf([c{:}],'[%f,%f,%f,%f]',[4,Inf]).';
T = convertvars(T,'face',F);
T = convertvars(T,'imageFilename',@string) % optional, a bit slow.
7 Kommentare
Stephen23
am 12 Okt. 2021
"Unfortunately it results in this error"
Yes, because you are not supplying that tool with the data in the format that it requires. You are using the tool, which means that you have its documentation, which means that you can read its documentation and find out what are the specific needs for the data.
The error message also gives some hints, perhaps something like this might be what that tool needs:
S = load('faceDatasetGroundTruth.mat')
T = S.faceDataset
F = @(c)num2cell(sscanf([c{:}],'[%f,%f,%f,%f]',[4,Inf]).',2);
T = convertvars(T,'face',F)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Image Processing and Computer Vision 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!