how to read a file and convert to matrix format

i am reading a file which has the values in the form
v -0.141202 5 5
v 3 5 5
v 4 5 5
i want to convert this in the form of a cell ignoring space ie in the form of 3X4 matrix
Thanks in advance

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 9월 28일

1 개 추천

fid = fopen('filename.txt');
out=textscan(fid,'%s')
fclose(fid);
out=reshape(out{:},4,[])'

댓글 수: 2

Sharen H
Sharen H 2012년 9월 29일
I am trying to read multiple files i changed the code like this but i am getting some errors it says invalid identifier
for j =1:4
fid(j) = fopen( sprintf( 'Secret1%i.obj',j),'r' )
out(j)=textscan(fid(j),'%s')
fclose(fid(j));
out{j}=reshape(out{:},4,[])'
end
for jj =1:4
fid=fopen(sprintf('Secret1%d.obj',jj),'r' )
out=textscan(fid,'%s')
fclose(fid);
res{jj}=reshape(out{:},4,[])'
end

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

추가 답변 (1개)

Sumit Tandon
Sumit Tandon 2012년 9월 28일

0 개 추천

There are several options - e.g. using Import Wizard or TEXTSCAN command.
Check out this link for more ideas.

카테고리

도움말 센터File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by