How can I solve the problem 'Subscripted assignment dimension mismatch' in my looping progress?

조회 수: 3 (최근 30일)
I want to write vector to an array (matrix), but I get problem in the dimension of it. ntr is the number of trace. this is my code:
for i=1:ntr % read traces into panel
[seis(:,i),seqno(i),itr(i),irec(i),dt,offset,sdepth,selev,relev(i),...
xs,ys,xr(i),yr(i),cdp(i)]=segyin(fid);
if i==1
cdp(i) % list cdp as progress flag
end
if (ixs == 0)
xoff=[xoff;offset]; % build offset vector
else
xoff = [xoff;10*(i-1)-1500];
end
here is the error:
Subscripted assignment dimension mismatch.
Error in trpan (line 152)
[seis(:,i),seqno(:,i),itr(i),irec(i),dt,offset,sdepth,selev,relev(i),...

답변 (2개)

Walter Roberson
Walter Roberson 2015년 10월 6일
In the error message, the first output is given as seis(nsamp,i), but in the code segment, the first output is given as seis(:,i) . The code you are running is not the same as the code you posted.
Note that we do not know anything about segyin() and we do not know how you initialized your variables.
  댓글 수: 1
Kiswanto Ihsani
Kiswanto Ihsani 2015년 10월 6일
편집: Walter Roberson 2015년 10월 6일
i have revised the code. i just copy from my trial and error method.
this is the original function of segyin
function [trc,seqno,itr,irec,dt,offset,sdepth,selev,relev,...
xs,ys,xr,yr,cdp]=segyin(fid)
% nsamp=length(trc);
%read the trace header
[stuff,count]=fread(fid,4,'int');
if(count<4)
trc=nan;
seqno=nan; itr=nan; irec=nan; dt=nan;
offset=nan; sdepth=nan; selev=nan; relev=nan;
xs=nan; ys=nan; xr=nan; yr=nan; cdp=nan;
return;
end
seqno=stuff(1); irec=stuff(3); itr=stuff(4);
stuff=fread(fid,4,'char');
cdp=fread(fid,1,'int');
stuff=fread(fid,4,'char');
code=fread(fid,1,'short');
stuff=fread(fid,6,'char');
stuff=fread(fid,4,'int');
offset=stuff(1);relev=stuff(2);selev=stuff(3);sdepth=stuff(4);
stuff=fread(fid,16,'char');
stuff=fread(fid,2,'short');
stuff=fread(fid,4,'int');
xs=stuff(1);ys=stuff(2);xr=stuff(3);yr=stuff(4);
lenunit=fread(fid,1,'short');
stuff=fread(fid,24,'char');
stuff=fread(fid,2,'short');
nsamp=stuff(1);dt=stuff(2)/1000000.;
%Note SEGY stores dt in microseconds
stuff=fread(fid,122,'char');
%trace header complete
%read in trace
trc=fread(fid,nsamp,'float');

댓글을 달려면 로그인하십시오.


Thorsten
Thorsten 2015년 10월 6일
The error seems to be due to the first two arguemnts. Try
[a,b,itr(i),irec(i),dt,offset,sdepth,selev,relev(i),...
xs,ys,xr(i),yr(i),cdp(i)]=segyin(fid);
whos a
whos b
What's the result? That may give you some idea of how to correct the code.
  댓글 수: 5
Kiswanto Ihsani
Kiswanto Ihsani 2015년 10월 6일
the value of nsamp is absolutely positive, based on the my previous experience, nsamp value more than 50.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by