Borrar filtros
Borrar filtros

how to read a file and convert to matrix format

2 visualizaciones (últimos 30 días)
Sharen H
Sharen H el 28 de Sept. de 2012
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

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 28 de Sept. de 2012
fid = fopen('filename.txt');
out=textscan(fid,'%s')
fclose(fid);
out=reshape(out{:},4,[])'
  2 comentarios
Sharen H
Sharen H el 29 de Sept. de 2012
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
Azzi Abdelmalek
Azzi Abdelmalek el 1 de Oct. de 2012
for jj =1:4
fid=fopen(sprintf('Secret1%d.obj',jj),'r' )
out=textscan(fid,'%s')
fclose(fid);
res{jj}=reshape(out{:},4,[])'
end

Iniciar sesión para comentar.

Más respuestas (1)

Sumit Tandon
Sumit Tandon el 28 de Sept. de 2012
There are several options - e.g. using Import Wizard or TEXTSCAN command.
Check out this link for more ideas.

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by