importing a text file into a vector
importing a text file into a vector
(OP)
I have a text file and i would like to read its content into a vector x in my m file, i looked at help section in Matlab and tried many function but it still doesnt work, does anyone know how to do it .. e.g
content of my text file is and its in the directory C:\work\work.txt
A former senior Partner whose association with the firm dates back to 1958, John "retired" in 1995 only to come back as the firm's Specialist Consultant in Clinical Negligence. A member of the Law Society Clinical Negligence panel, John has a formidable reputation both locally and regionally.
Educated at Gordonstoun and Liverpool University, John qualified as a solicitor in 1958 after "articles" in a practice on Merseyside.
i tried to command in my m file as
[x] = textread('C:\work\work.txt ','%c')
i am not quite sure which format i should use, but all the content in my text file are ASCII character ...
content of my text file is and its in the directory C:\work\work.txt
A former senior Partner whose association with the firm dates back to 1958, John "retired" in 1995 only to come back as the firm's Specialist Consultant in Clinical Negligence. A member of the Law Society Clinical Negligence panel, John has a formidable reputation both locally and regionally.
Educated at Gordonstoun and Liverpool University, John qualified as a solicitor in 1958 after "articles" in a practice on Merseyside.
i tried to command in my m file as
[x] = textread('C:\work\work.txt ','%c')
i am not quite sure which format i should use, but all the content in my text file are ASCII character ...





RE: importing a text file into a vector
x=importdata('hey.txt');
If the file hey.txt contains the text: "Hey, how are u",
Matlab will display in the command window (upon entering 'x'):
'Hey, how are u'
RE: importing a text file into a vector
x=importdata('hey.txt');
can display the content of hey.txt on the command window.. but i want the number of characters inside the file hey.txt store into the variable x so that i can use the variable x to do some other task, do u know how to do it ??
RE: importing a text file into a vector
fid = fopen('C:\work\work.txt ');
b=fscanf(fid,'%c')
c = length(b)
fclose(fid)
This one just finds the length of the string (including whitespace characters).
The trouble with textread is that it automatically assumes you want to ignore whitespace, or use whitespace as delimiters.
Don't know what you want to do with the string, but this should at least get it into matlab to manipulate it.