2012-02-20 74 views
0

我已经写一个for循环在其中沿着每个使得它们中的列的相应的分割5000行。包含这些行中的单元阵列的做一个字符串分割为多行中MATLAB

实施例: enter image description here

从这张图片中,我想分别沿着它们各自的列开始从第一列开始到结束每一行。

这是我写的代码:

for i = pdbindex(:,1) 

    clean_pdb = regexprep(pdbindex, ':', ' '); % removes the colon (:) from the array and replaces it with a whitespace 
    pdb2char = char(clean_pdb); % converts the cell array into a character array 
    pdb2split = strsplit(pdb2char, ' '); % does a split based on the character array followed by a delimiter, which is the white space 

end 

我用正则表达式替换冒号(:),一个空格。然而,它给我一个错误,说明Input strings must have one row.。我不知道如何解决这个问题。

请指教。

+1

看起来你的第一行是空的。试试'for i = pdbindex(2:end,1)'。 – Pursuit 2012-02-20 19:21:53

+0

我的歉意。我已经完成了对单元阵列的修改。我已将鼠标光标移动到行上,并在我测试了for循环后回车。 – Jeiman 2012-02-20 19:26:26

回答

2

我会做这样的:

%Some sample data 
data = {'1 : 2 : 3 :4: 5: 6';'7 :8 : 9: 10 :11 :12'}; 

除法都是基于分隔符行(分隔符是空格和任意的组合“:”)

splitData = regexp(data,'[\s\:]*','split') 

现在将拆分数据可以被读出为

example = splitData{row}{column}; 

很可能你会希望将它转换为数字(而不是字符串)。你可以像这样一次做到这一行:

numericRow = num2double(splitData{rowNumber});