Removing a character from a table (that's within a struct)
7 ビュー (過去 30 日間)
古いコメントを表示
Yonathan Zarkovian
2021 年 10 月 7 日
コメント済み: Yonathan Zarkovian
2021 年 10 月 13 日
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 件のコメント
C B
2021 年 10 月 7 日
編集済み: C B
2021 年 10 月 8 日
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 =
']'
採用された回答
Stephen23
2021 年 10 月 8 日
編集済み: Stephen23
2021 年 10 月 8 日
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 件のコメント
Stephen23
2021 年 10 月 12 日
"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)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Image Processing and Computer Vision についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!