How to solve this error index in position 1 exceeds array bounds?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
Hi,
How I can correct this error?
Index in position 1 exceeds array bounds (must not exceed 128).
Error in Create_Obs_dataL (line 60)
synth = synth(1+t0_i:nt+t0_i,:);
Accepted Answer
Cris LaPierre
on 26 Jan 2022
The error is that your indexing of rows (specifically nt+t0_i), is resulting in a number higher that the total number of rows in your matrix. Here's a simple example:
A = rand(2,1)
A = 2×1
0.8538
0.6416
% Works
A(2,1)
ans = 0.6416
% Your error
A(3,1)
Index in position 1 exceeds array bounds. Index must not exceed 2.
6 Comments
Nisar Ahmed
on 26 Jan 2022
Edited: Cris LaPierre
on 26 Jan 2022
@Cris LaPierre How to overcome this error, this is my code
nt = 115;
f0 = 50;
wr = 2*pi*1;
t0 = 2/f0;
t0_i = floor(t0/dt);
Unrecognized function or variable 'dt'.
wav = Ricker(f0,t0, nt, dt).';
th = (0:25)*pi/180;
nt = length(wav);
nw = 2^nextpow2(nt);
nwr = (nw/2 +1);
dw = 2*pi/(nw*dt);
w = (0:nwr-1)*dw;
w(w<2)=2;
[THETA,W] = meshgrid(th,w);
%% Compute reflection coefficients
Rsde = abco(vp,vs,rho,qp,qs,THETA, wr, W);
%%
Rsde_fft = fft(Rsde,nw);
wav_fft = fft(wav,nw);
synth_fft = zeros(size(W));
% % Multiply positive frequencies
for i=1:nwr
synth_fft(i,:) = Rpp_fft(i,i,:)*wav_fft(i);
end
% Build negative frequencies
synth_fft(nwr+1:nw,:) = conj(synth_fft((nwr-1):-1:2,:));
synth=real(ifft(synth_fft));
synth = synth(1+t0_i:nt+t0_i,:);
Nisar Ahmed
on 26 Jan 2022
Rsde_fft = Rpp_fft
Cris LaPierre
on 26 Jan 2022
The way to fix it is to make sure nt+t0_i is less than 128.
Currently, dt is not defined, so perhaps your code is not using the value for dt that you intended. This will impact the value of t0_i
Nisar Ahmed
on 26 Jan 2022
dt is there dt = 0.001, dt is there, I just not mentioned
Nisar Ahmed
on 26 Jan 2022
actuall, when my data point was nt = 260, it is working well. but as in new data points nt = 115, it started giving error
Cris LaPierre
on 26 Jan 2022
nt = 115;
f0 = 50;
t0 = 2/f0;
dt = 0.001;
t0_i = floor(t0/dt)
t0_i = 40
nt+t0_i
ans = 155
Apparently your matrix has 128 rows, and you are trying to access the 155th, hence the error. Your equation does not appear to scale correctly with nt. You need to figure out what the correct value should be, and adjust your math accordingly.
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)