MATLAB Answers

How to delete an element from a cell

2 views (last 30 days)
Maria
Maria on 26 Apr 2014
Commented: Maria on 24 Jun 2014
I have a column in matlab with data written this way:
19970422
30980524
63098754
etc …
And I only want to have the first 4 numbers (preferably as a new variable), for instance like this:
1997
3098
6309
How can I do it? Thanks a lot for your help.

Accepted Answer

Apdullah YAYIK
Apdullah YAYIK on 27 Apr 2014
Edited: Jan on 27 Apr 2014
Thats easy
X=[19970422 30980524 63098754]
New_X=floor(X/1000)
  2 Comments
Image Analyst
Image Analyst on 27 Apr 2014
And she said she had cells, not regular numerical arrays, though perhaps she didn't really mean cells - who knows.

Sign in to comment.

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 26 Apr 2014
Edited: Azzi Abdelmalek on 26 Apr 2014
a=[19970422;30980524;63098754]
b=arrayfun(@num2str,a,'un',0)
out=cellfun(@(x) str2num(x(1:4)),b)
%or
a=[19970422;3098052422;630987541;0.23]
n=max(0,fix(log10(a)+1)-4)
out=fix(a./10.^n)
  2 Comments
Maria
Maria on 24 Jun 2014
About this question, problem solved!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by