extract_words.m

来自「基于Matlab的地震数据处理显示和测井数据显示于处理的小程序」· M 代码 · 共 38 行

M
38
字号
function words=extract_words(string)% Function extracts character groups from input character string "string" and stores% them in a cell array; character groups must start with a letter and can contain numbers and% underscores.% Written by: E. R.: Date March 4, 2000;% Last updated: December 7, 2000: words must satisfy the same rules as MATLAB variables% INPUT % string	String to be analyzed% OUTPUT% words         Cell array containing all contiguous groups of letters including underscores%            words=extract_words(string)idx=(isletter(string) | string == '_' | (double(string) > 47 & double(string) < 58));didx=diff([0,idx,0]);index=find(didx ~= 0);nw=length(index);if nw == 0  words=cell(0);else  for ii=1:2:nw    words((ii+1)/2)={string(index(ii):index(ii+1)-1)};  endend%       Eliminate words that start with a numbercount=0;% keyboardfor ii=1:length(words);  if isletter(words{ii}(1))    count=count+1;    words(count)=words(ii);  endendwords(count+1:length(words))=[]; 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?