Importing and saving big text data to MATLAB format -


i have big txt files (~25mb). don't open in excel , doesn't work try import it.

using following comands can read there inside... can not save matlab file use other data.

i'm trying:

fid = fopen('file.txt') while~feof(fid) tline = fgets(fid); disp(tline); end  

i tried both fgets() , fgetl(). reads entire file. doesn't store information in workspace.

if variable tline not exist in matlab workspace after run code, it's possible running in function instead of script. in addition, need save each line read in array of kind doesn't overwritten next line read in. i.e.

function foobar(foo,bar) fid=fopen('file.txt') n = 0;   while~feof(fid)      tline=fgets(fid);      disp(tline);     n = n + 1;     data{n} = tline; end 

if calling in function, commenting out function line cause variables persist in workspace.

alternatively add line of code save variables need mat file , open later.

function foobar(foo,bar) fid=fopen('file.txt') n = 0;   while~feof(fid)      tline=fgets(fid);      disp(tline);     n = n + 1;     data{n} = tline; end fclose(fid); save('filename.mat','data'); 

and workspace run

load('filename.mat'); 

note: data may not need cell. depends on type of data in file


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -