How to extract the first four and last four digits of all numbers of an array where each number is of 12 digits?
    9 次查看(过去 30 天)
  
       显示 更早的评论
    
I have an array of over 200,000 numbers. Each of these numbers is of 12 digits. I want to extract and form another array with: (1) the first four digits of the original array, (2) the last four digits of the original array. How can it be done? 
For example if one of the numbers of the array is 123456789012, then the output to (1) should be "1234" and output to (2) should be "9012".
2 个评论
  DGM
      
      
 2021-3-24
				Is this a strictly numeric array or a cell array of strings/chars imported from a file?
采纳的回答
  DGM
      
      
 2021-3-24
        
      编辑:DGM
      
      
 2021-3-24
  
      Try this
% this is my example data
num=[152012073637; ...
     325081863583; ...
     841721647389; ...
     648968298758; ...
     346301193257; ...
     595880316669];
numhead=floor(num/1E8)
numtail=mod(num,1E4)
the results are:
numhead =
        1520
        3250
        8417
        6489
        3463
        5958
numtail =
        3637
        3583
        7389
        8758
        3257
        6669
2 个评论
更多回答(0 个)
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


