Borrar filtros
Borrar filtros

While Loop column vector of strings

2 visualizaciones (últimos 30 días)
Bob Whiley
Bob Whiley el 25 de Feb. de 2015
Respondida: dpb el 25 de Feb. de 2015
I am trying to make a column of names and a column of numbers given a .txt file. The names are always next to the number, with a ';' in between them. The way my code is set up, it looks like
fh = fopen('phoneList1.txt');
line = fgetl(fh);
vec = [];
numbers= [];
while (ischar(line))
[checkstuff, yak] = strtok(line, ';');
[blah, bleh] = strtok(yak, '(');
vec = [checkstuff vec];
numbers = [bleh numbers];
line = fgetl(fh);
end
fclose(fh);
But my vec output returns a one-by-one vector of all the names combined into one string with no spaces in between them, how can I give each name its own row?

Respuestas (1)

dpb
dpb el 25 de Feb. de 2015
If these are formatted phone numbers, they're text, too...
fh = fopen('phoneList1.txt');
c=textscan(fh,'%s %s','delimiter',';','collectoutput',1);
You'll have a cell array of Nx2, the first column will be the names the second the numbers.

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by