how to remove the first 5 characters from a cell array 343x1 cell
45 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
NU_YU
am 27 Okt. 2015
Kommentiert: Leone Campos
am 5 Jan. 2023
Hello all, I would like to remove the first few characters from every single cell (343), yet I am not much aware of how to do it. I tried to solve the problem via googling it yet could not find anything that would fit my case. The cell array is attached. Example: for "d035-117" for instance i would like to convert it into a form of "117". The first 5 characters need to be truncated. Thanks for your advices and help in advance!
2 Kommentare
Image Analyst
am 7 Dez. 2022
@Jack you can see he accepted my answer below so I guess it worked for him.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
Akzeptierte Antwort
Image Analyst
am 27 Okt. 2015
How about (untested)
for k = 1 : length(ca)
cellContents = ca{k};
% Truncate and stick back into the cell
ca{k} = cellContents(6:end);
end
5 Kommentare
Supriya Gain
am 18 Mai 2022
I have a folder which contains 389 CSV files. And each CSV file has a dimension of 82x1. So basically it's a 1D matrix. Now the first element (i.e. A1) of every CSV file is 'VAR'. Now I want to remove this 'VAR' and shift my matrix to the upside. That means I want to remove A1 element and shift the whole matrix from A1. How to do that.
Image Analyst
am 18 Mai 2022
@Supriya Gain try reading it into a table and deleting the first column
t = readtable(filename);
t = t(:, 2:end)
If that doesn't work, start a new question of your own (not here) and attach one of the CSV files there.
Weitere Antworten (1)
Jos (10584)
am 27 Okt. 2015
Bearbeitet: Jos (10584)
am 27 Okt. 2015
If A is your cell-array of strings, this oneliner will do the job:
B = cellfun(@(x) x(1:end-5), A, 'un', 0)
2 Kommentare
Leone Campos
am 5 Jan. 2023
For those who are wondering what 'un' is, it stands for 'UniformOutput'.
Siehe auch
Kategorien
Mehr zu Data Type Conversion 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!