Hello guys,
I have this function that reads and stores data from a file:
function [data] = read() [file,path] = uigetfile('.txt'); fid = fopen(fullfile(path, file), 'rt');READS UNTIL END OF HEADERtline = fgets(fid);while (~strcmp(tline(1:3),'END'))tline = fgets(fid);endk=0;while ~feof(fid) tline = fgets(fid);sat=tline;index=strfind(tline,'G');[~,n]=size(index) ;A = zeros(4,n);for i=1:n A(1,i)=str2num(sat(index(i)+1:index(i)+2)); tline = fgets(fid); a= sscanf(tline,'%f'); A(2:4,i) = [a; NaN(2-length(a),1)];endk = k+1;data(k).info=A;endend
and this is the exemple of the file that contains my data:
THIS HEADER CONTAINSINFORMATION AND OTHERTHINGS THAT ARE NOT NEEDEDAT THE MOMENTEND OF HEADER4G05G16G21G2560000 30000 1000060001 30001 1000260002 30002 1000160003 30003 100033G02G03G1550000 20000 1000150001 20001 1000250002 20002 100014G06G11G17G2030000 10000 1000130001 10005 1000830002 10002 1000130003 10003 10004
The function works fine BUT I wonder if I can access the data from my file WITHOUT storing it. In case I have a larger file, this function takes too long to run. In the example I posted, as you see I have 3 blocks of data but my original file have 2880 blocks..It take like 10 seconds for my function to read and store and afterwards I need to use that data for different algorithms. Is there any way to access the information directly from the file and use it in formulas/algorithms?
Thank you very much.
PS: I have attached both of the files in case someone have some spare time to throw a look.
Best Answer