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

8 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Image Analyst
Image Analyst il 25 Giu 2019
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;
end
That's untested so it might need some tweaking. Attach your table in a .mat file if you need more help.
  1 Commento
Mihai Ciortuz
Mihai Ciortuz il 25 Giu 2019
Modificato: Mihai Ciortuz il 25 Giu 2019
I used this one because I had the first column as a cell before so it was easier this way.
cellX = cellfun(@(x) x(111:end-7), cellX, 'UniformOutput', false); % I needed the first 111 characters and last 7 chopped off
Thanks for the help!

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by