Using while ~feof(fid) - Subscripted assignment dimension mismatch.
16 次查看(过去 30 天)
显示 更早的评论
I need to read and extract the data from my file (I have attached it). In order to do this I made this function:
function [obs] = readRINEXobs()
%Opening the selecting menu
[file,path] = uigetfile('*.**o');
%Opening the file
fid = fopen(strcat(path,file),'r');
%Reading until END of HEADER
tline = fgets(fid);
while (~strcmp(tline(61:63),'END'))
tline = fgets(fid);
end
tline = fgets(fid);
sat=tline;
index=strfind(tline,'G');
[~,n]=size(index);
while ~feof(fid)
for i=1:n
A(1,i)=str2num(sat(index(i)+1:index(i)+2));
tline = fgets(fid);
A(2:6,i) = sscanf(tline,'%f');
tline = fgets(fid);
A(7,i) = str2num(tline);
end
end
obs.data=A;
end
But I get this error
Subscripted assignment dimension mismatch.
Error in readRINEXobs (line 25)
A(2:6,i) = sscanf(tline,'%f');
The lines of the blocks of data are not constant, some blocks have 7 lines, some have 8, 9 and so on. Anyone can help me?
0 个评论
采纳的回答
dpb
2014-6-3
编辑:dpb
2014-6-4
...The lines of the blocks of data are not constant, some blocks have 7 lines, some have 8, 9 and so on
The first number in the block ID string is the number of records --
13 03 12 00 00 0.0000000 0 7G05G16G21G25G29G30G31
indicates there are 7 records in the following block. Change your routine slightly to read the line block then create a dynamic SIZE count to read that many records of values in the fscanf statement. It's kinda' a pita there's a record break in the data but you can work that out in the format string.
Once you change to read the counted number, then the next record should always be the next block header and repeat...
ADDENDUM
Had a few minutes to play...try the following for starters--
>> fid=fopen('rinexobs.13o','r'); % open
>> l=[];while isempty(strfind(l,'END'));l=fgetl(fid);end % skip header
>> n=fscanf(fid,[repmat('%*f',1,7) '%dG']',1); % read record count
>> fgetl(fid); % finish off record
>> n
n =
7
>> cell2mat(textscan(fid,repmat('%f',1,6),n,'collectoutput',true,'delimiter','\n'))
ans =
1.0e+08 *
0.2318 1.2181 -0.0000 0.2318 0.9491 -0.0000
0.2390 1.2559 0.0000 0.2390 0.9786 0.0000
0.2162 1.1363 0.0000 0.2162 0.8855 0.0000
0.2259 1.1870 -0.0000 0.2259 0.9249 -0.0000
0.2059 1.0820 -0.0000 0.2059 0.8431 -0.0000
0.2144 1.1267 0.0000 0.2144 0.8780 0.0000
0.2259 1.1872 -0.0000 0.2259 0.9251 -0.0000
>> n=fscanf(fid,[repmat('%*f',1,7) '%dG']),fgetl(fid);
n =
8
>> cell2mat(textscan(fid,repmat('%f',1,6),n,'collectoutput',true,'delimiter','\n'))
ans =
1.0e+08 *
0.2318 1.2183 -0.0000 0.2318 0.9493 -0.0000
0.2497 1.3121 0.0000 0.2497 1.0224 0.0000
0.2388 1.2549 0.0000 0.2388 0.9779 0.0000
0.2161 1.1358 0.0000 0.2161 0.8850 0.0000
0.2261 1.1880 -0.0000 0.2261 0.9257 -0.0000
0.2060 1.0823 -0.0000 0.2060 0.8434 -0.0000
0.2143 1.1260 0.0000 0.2143 0.8774 0.0000
0.2260 1.1878 -0.0000 0.2260 0.9256 -0.0000
>>
Wrap the above in a loop. Since it's a sizable file you'll want to either preallocate or use a cell array to accumulate the various blocks depending on how you need the results. I just wrapped the textread in a cell2mat call here to show the results; salt to suit your needs.
If you need more of the block header info, parse the line more fully; again I just snagged the leading number then trashed the rest of the record here...
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!