Filter löschen
Filter löschen

how to return first 5 digits of 6th column in cell array?

2 Ansichten (letzte 30 Tage)
Jeff
Jeff am 6 Apr. 2014
Kommentiert: Jeff am 6 Apr. 2014
Hi Matlab community,
Here's another newbie question. I would like to replace the 6th column with the first 5 digits of that column (20134); I would then like to create a 7th column that is the last digit of the 6 column. Here's a sample array.
Thank-you for your help.
cell = {'this' 'is' 'a' 'cell' 'array' '2013420134' }

Akzeptierte Antwort

Jeff
Jeff am 6 Apr. 2014
Ok found it; thanks anyway all
cell{1,5}(1:5)

Weitere Antworten (1)

Jos (10584)
Jos (10584) am 6 Apr. 2014
C = {'this' 'is' 'a' 'cell' 'array' '2013420134' }
V = C{6} % retrieve the 6th cell
C{6} = V(1:5) % replace it
C{7} = V(end) % add a new cell
btw, avoid giving your variable the same name as a matlab function
  1 Kommentar
Jeff
Jeff am 6 Apr. 2014
Thanks Jos for showing the alternative. Thanks for pointing out my ridiculous variable name, picked it quick for the example.
I basically ended up using a loop since there are close to 17000 variables
[m,n]=size(data); for i = 1:m data1{i,9} = data{i,9}(1:5); data{i,9} = {}; data{i,9} = data1{i,9}; end
Just having fun in matlab on a sunday night :)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices 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!

Translated by