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

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 件のコメント

I got all of the parameters in segyin like this:
ntr = 7
Name Size Bytes Class Attributes
a 0x0 0 double
Name Size Bytes Class Attributes
b 1x1 8 double
ans =
101056512
but it produce the other error
Error using fread
Invalid size
trc=fread(fid,nsamp,'float')
I used 'float' as my precision to read binary data
Walter Roberson
Walter Roberson 2015 年 10 月 6 日
nsamp is somehow invalid, such as if it is negative. You are reading it as 'short' which is a signed value.
Kiswanto Ihsani
Kiswanto Ihsani 2015 年 10 月 6 日
i have give absolute value for nsamp, so it to be nsamp=abs(nsamp). as the result it will give positive value in all of the range. actually this code is an old code, it has build for more than 12 years ago, I am so tired to check it one by one. When one line is clear, there is a problem in the other line.
Thorsten
Thorsten 2015 年 10 月 6 日
What's the value of nsamp? Could it be 0?
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.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2015 年 10 月 6 日

コメント済み:

2015 年 10 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by