While Loop column vector of strings
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
dpb
2015 年 2 月 25 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!