MATLAB: Can you remove certain characters from first column and each row of a table

MATLABmatlab tables table column remove text

I have this table:
files aMean
_____________________________ __________________
'C:\Users\dexte\OneDrive\Desktop\1' 3.38904290625e-10
'C:\Users\dexte\OneDrive\Desktop\2' 3.727809984375e-12
'C:\Users\dexte\OneDrive\Desktop\3' 4.03381559375e-10
'C:\Users\dexte\OneDrive\Desktop\4' 3.550222328125e-10
'C:\Users\dexte\OneDrive\Desktop\5' 3.75777240625e-10
'C:\Users\dexte\OneDrive\Desktop\6' 4.319917984375e-12
'C:\Users\dexte\OneDrive\Desktop\7' 4.1586619375e-10
I would like to have 1, 2 ,3, 4 in the first column instead of getting the whole filepath. Any help?

Best Answer

  • In a loop, get the filename and extract the last character(s) that are the number or use fileparts. Untested code:
    for k = 1 : size(t, 1)
    thisFileName = t.files{k}
    [folder, number, ext] = fileparts(thisFileName)
    t.files{k} = number;
    That's untested so it might need some tweaking. Attach your table in a .mat file if you need more help.