How to extract data from table variable names?
Mostrar comentarios más antiguos
MIM Maestro puts volume data inside the table variable names:
Rectum (4)(Volume: 57.77) Bladder (5)(Volume: 139.40)
How do we extract this volume data?
Respuestas (2)
Daniel Bridges
el 14 de Mzo. de 2018
>> C = {'Rectum (4)(Volume: 57.77)','Bladder (5)(Volume: 139.40)'};
>> str2double(regexp(C,'\d+(\.\d+)?(?=\)$)','once','match'))
ans =
57.770 139.400
Or to require the preceding 'Volume' substring:
str2double(regexp(C,'(?<=Volume: )\d+(\.\d+)?(?=\)$)','once','match'))
6 comentarios
Daniel Bridges
el 14 de Mzo. de 2018
Editada: Daniel Bridges
el 14 de Mzo. de 2018
Daniel Bridges
el 14 de Mzo. de 2018
Stephen23
el 14 de Mzo. de 2018
@Daniel Bridges: sorry, my old MATLAB can't read that object type. Please upload this .mat file:
vn = opts.VariableNames;
save('varnames.mat','vn')
Daniel Bridges
el 15 de Mzo. de 2018
@Daniel Bridges: thank you for uploading that .mat file. The char vectors in that cell array have a different format to the one that you showed in your question, apparently with the parentheses and decimal point replaced by underscores. You can easily process this by first replacing the underscore with period characters:
>> S = load('varnames.mat');
>> C = strrep(S.vn,'_','.');
>> str2double(regexp(C,'\d+(\.\d+)?(?=\.$)','once','match'))
ans =
Columns 1 through 7
NaN 18494 27.49 4.9 57.77 139.4 479.8
Columns 8 through 14
1.08 29.15 95.8 97.26 72.3 93.45 80.69
Columns 15 through 16
83.06 32.39
As an alternative you could skip using detectImportOptions (which I guess makes these character replacements) and read the header lines using fgetl. This line could then be trivially process by a similar regular expression to the one I showed you.
Categorías
Más información sobre Data Distribution Plots en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!