Split Cell by Linebreak then Delimiter

2 views (last 30 days)
Roi Abrazaldo
Roi Abrazaldo on 15 Mar 2014
I am having a problem to do both at the same time.
This is my sample data from a text file:
FirstName|LastName|Country
Jake|Abraham|US
Nigel|Brook|US
Mila|Niz|Canada
I pass those data to a variable and wanted to split it via '|' pipe delimiter and linebreak
content = regexp(content,'\|\r\n','split');
above outputs the structure I wanted but theres 1 mistake the cell never shift to next line it only continues to the first cell lines
[ FirstName ][ LastName ][ Country ][ Jake ][ Abraham ][ US ][ Nigel ][ Brook ][ US ][ Mila ][ Niz ][ Canada ]
the output I was trying to accomplish is this:
[ FirstName ][ LastName ][ Country ]
[ Jake ][ Abraham ][ US ]
[ Nigel ][ Brook ][ US ]
[ Mila ][ Niz ][ Canada ]
so it will look right when I attached the cell variable to the uitable I wanted to attach the output data to the uitable.
I manage to do it using loop with this code:
container = {};
row = {};
content = regexp(content,'\r\n','split');
content = cellfun(@(x) regexp(x,'\|','split'), content, 'UniformOutput', false)';
content(end) = [];
for x = 1:length(content)
row = content{x};
container = [container ; row];
end
but it takes too much time to process 100k+ lines
is there a possible way to apply both split rule faster?

Answers (0)

Categories

Find more on Cell Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!