【发布时间】:2012-03-11 03:12:12
【问题描述】:
我编写了一个 for 循环,在其中沿它们所在的每一列相应地拆分 5000 行。
包含这些行的元胞数组示例:
从那张图片中,我想从第一列到最后,沿着该行各自的列相应地拆分每一行。
这是我写的代码:
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.。我不知道如何解决这个问题。
请指教。
【问题讨论】:
-
看起来您的第一行是空的。试试
for i = pdbindex(2:end,1)。 -
我很抱歉。我已经对我的单元格数组进行了修改。在测试了 for 循环后,我将鼠标光标移到该行上并按 Enter。
标签: matlab for-loop char strsplit