While Loop column vector of strings
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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?
0 Kommentare
Antworten (1)
dpb
am 25 Feb. 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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Cell Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!