I have written a for loop in which to split 5000 rows accordingly along each of the columns that they are in.
Example of the cell array that contains those rows:
From that picture, i would like to split each row accordingly along their respective columns of that row starting from the first column to the end.
This is the code that i have written:
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
I have used Regular Expressions to replace the colons (:), with a whitespace. However, it is throwing me an error stating Input strings must have one row.
. I don't know how to solve this.
Please advise.
I would do this like this:
%Some sample data
data = {'1 : 2 : 3 :4: 5: 6';'7 :8 : 9: 10 :11 :12'};
The Divide all the rows based on delimiters (a delimiter is any combinations of white space and ":")
splitData = regexp(data,'[\s\:]*','split')
Now your split data can be read out as
example = splitData{row}{column};
Most likely you will want to convert this to numbers (not strings). You can do this one row at a time like this:
numericRow = num2double(splitData{rowNumber});