Is textscan the correct command to use when importing data from text files into matlab. The command seems to work fine if I only have a vector in the text file, but if I have a matrix, matlab will change the structure of the data and store the matrix as a vector. Which command should I use if I'm importing data from text files within a loop where some of the text files include vectors and others include matrices?

 채택된 답변

Oleg Komarov
Oleg Komarov 2012년 2월 23일

0 개 추천

You have to specify the right 'format', read example 8 to get an idea: http://www.mathworks.co.uk/help/techdoc/ref/textscan.html

댓글 수: 3

Richard
Richard 2012년 2월 23일
So, if I have say 4 .txt files in a folder where 2 are column vectors and the other 2 are matrices I would have to use textscan twice in order to obtain all of the values. By using:
fid = fopen('...');
a = textscan(fid,'%f');
It returns the text files which should be matrices as one long vector.
Richard
Richard 2012년 2월 23일
I've decided to use dlmread seeing as the .txt files do not have any headings.
Oleg Komarov
Oleg Komarov 2012년 2월 23일
Headers do not matter, if you want 4 columns the right format is:
textscan(fid,'%f %f %f %f','Delimiter',''whateveryoulike')
or
textscan(fid,'%f',4,'Delimiter',''whateveryoulike')

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

질문:

2012년 2월 23일

편집:

2013년 10월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by