我在这里遇到了一个问题,我有一个像下面这样的单元格。两个向量,每行有一个数字或首字母缩略词
' 33572' ' AGCHIN'
' 46058' ' ABCHIN'
' Commercial Bank' ' 48188'
' 45913' ' NINGBO'
' Commercial Bank' ' 46701'
' Commercial Bank' ' 30118'
' Commercial Bank' ' 33076'
' Commercial Bank' ' 46799'
' 40749' ' BITICLTD'
' 40440' ' PARICHIN'
' Commercial Bank' ' 18925'
' 16911' ' CHANGSHA'
' 40220' ' CHENGDU'
' 32748' ' CHISO'
' Commercial Bank' ' 32378'
' 48206' ' CCBIAS'
' Non-banking Credit Institution' ' 23729'
' Specialised Governmental Credit Inst.' ' 43960'
' Commercial Bank' ' 38203'
' 38600' ' CHMBIAS'
' 45809' ' MINSHENG'
' 23601' ' PINGANTI'
' Commercial Bank' ' 42330'
' 45550' ' CHINESE'
' 49481' ' CHONGS'
' Investment Bank/Securities House' ' 32365'
' 23602' ' CITITI'
' 39611' ' LUOYANG'
' 19950' ' DALICITY'
' 23603' ' DAILIANH'
' 17360' ' DONGGUAN'
' 23604' ' DONGGUTI'
' 39612' ' DONGYING'
' 39060' ' EVERGBC'
' 42596' ' EXPO'
' 46703' ' SINOBKU'
' 34608' ' FUJIAN'
' 29182' ' FUZHOU'
' 35965' ' GUANGDON'
' 29375' ' GRCCOOP'
' 29462' ' GUOLIAN'
' 29490' ' HAITONG'
' 18565' ' HANGZIAS'
' 23730' ' HANGZICT'
' 23758' ' HARBIN'
' 23420' ' HEFEI'
' 48411' ' HETLONG'
' 44174' ' HUAX'
' Commercial Bank' ' 29149'
' 23421' ' HUNAN'
我想提取数字并将数字放入一列,有人能告诉我该怎么做吗?谢谢!
答案 0 :(得分:5)
如果我理解正确,您需要提取数字并将它们放入单个列中。为此,你必须过滤掉非数字。
Cstr = cellfun(@str2num, {C{:}}, 'Uniform', 0); % # Convert strings to numbers
Cnums = Cstr(cellfun(@(v)~isempty(v), Cstr)); % # Remove empty strings
删除空单元格,因为str2num
在包含非数字字符的字符串上运行时会生成空向量。
现在我们有一个只包含数字的单元格数组。要将单元格数组转换为列向量,只需执行:
nums = [Cnums{:}].'
它应该产生以下结果:
nums =
33572
46058
45913
40749
40440
16911
40220
32748
48206
...