how to remove the first 5 characters from a cell array 343x1 cell

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 Commenti

Do you have the answer already, because i don't get it too?
@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:

Accedi per commentare.

 Risposta accettata

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 Commenti

Dear Image Analyst,
Thank you for the link, it is quite helpful. Using your script I got some unnecesary stuff in the output but probably it is because of my data. Many many THANKS! :)
Well post your data. Maybe it's not always the first 5 characters that need to be removed. Maybe you need to search for a "-" dash location or something.
I am sorry, all is good. I got it wrong. Your script works perfectly. Highly appreciated. May I ask you an additional question, I want to convert the cell into numeric and plot it, or may i plot it as it is? (i don't know, but it gives and error message). i tried out cell2mat (that was the only i could find (there is no cell2num option) yet that one gave me funny answers, like "cell2mat(name(012))
ans =
036
>> cell2mat(name(036))
ans = 108". What would you suggest me to do?
Thank you!
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.
@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.

Accedi per commentare.

Più risposte (1)

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 Commenti

Hi Jos,
I am not good at in matlab, so i sound dumb for sure. I did what you had suggested and it worked for the first 3 characters, not for the last 3. i substituted it with x(6:9), but it gace me an error. anyhow, thanks! I will try to solve it somehow. much appreciated
For those who are wondering what 'un' is, it stands for 'UniformOutput'.

Accedi per commentare.

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by