import multi type data in MATLAB

How I can import a text file in MATLAB including 256 columns: first column is string and other columns are numeric data.

 Akzeptierte Antwort

Gerd
Gerd am 29 Jun. 2011

0 Stimmen

Hi Sarah,
depending on your specific file you can use
fid= fopen('File.txt');
textscan(fid,'%s%f.....');
fclose(fid);
Gerd

6 Kommentare

SARAH ZAVAREH
SARAH ZAVAREH am 29 Jun. 2011
Hi Gerd,
Thanks for your answer.
My problem is that I have 255 columns of %f(numeric). How I can mention this larg number of %f in this command?!!
Oleg Komarov
Oleg Komarov am 29 Jun. 2011
['%s' repmat('%f',1,255)]
SARAH ZAVAREH
SARAH ZAVAREH am 29 Jun. 2011
Hi Oleg,
What about left hand side of this command?
???=textscan(fid,['%s' repmat('%f',1,255)]);
Gerd
Gerd am 29 Jun. 2011
On the left hand side is your variable
Jan
Jan am 29 Jun. 2011
Data = textscan(fid,['%s' repmat('%f',1,255)]);
Then Data is a cell, which contains the different columns as elements. See "help textscan".
SARAH ZAVAREH
SARAH ZAVAREH am 29 Jun. 2011
Thank you all, it works :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by