Dear All,
I need to read a txt file which contains a list of names with different lengths. Here is my txt file:
mynames:
OAKFIELD
5556_T
ROLLINS
……
I need to read those names to store them in a string array MyNames. MyNames should be like below:
MyNames = [
'OAKFIELD'
'5556_T'
'ROLLINS'
……
];
Here is my code:
fid = fopen(FileName, 'r');
if fid < 0, error('Cannot open file'); end
while KKK < 30000 % Infinite loop
s = fgets(fid);
if ischar(s)
MyNames = [MyNames; s];
else % End of file:
break;
end
end
But what I got is Not correct. MyNames is an array having 10 coulmns and shows as
'CHSTRSVC←↵'
'5556_T'←↵'
'ROLLINS←↵'
…
Best Answer