41 viewsJuly 13, 2021matlabfor-loop indexing loops matlab matlab-figure Attribution: https://stackoverflow.com/q/68363757
*

I have actually a code to procedure my acoustic data (altimeter soundings to monitor seagrass heights in shallow water). The data comes in separate records for each survey section and also so I have a full of 6 various sized .txt docs. I have loaded everything in however when I try to average in a loop every 7 pings i am getting and also error.

You are watching: Index in position 2 exceeds array bounds


Index in place 2 exceeds variety bounds (must no exceed 27630) Error in VA500readv2 (line 55) tmp_depth = ping_depth(:,i-x:i+x); % find all depth worths for x pings before and also after ping i.
This is what the section of password looks like, any assist is lot appreciated. I will additionally copy the variable size in. Give thanks to you for help in advance.Also ns have currently ran the full script on two previous data files and also it worked absolutely fine so i am unsure what’s gone wrong once trying to operation the the third. Many thanks again.

I am trying to index 2 columns(time and pings) however I am no sure exactly how to execute this the best method :// listed below is fifty percent of mine code and the loops that I have actually been using, the little bit at the start (for loop and also k_ind) creates a procession the size of 28022 as soon as I require 27630 and I to be unsure how to fix this.


% index the VA500 pingsk = regexp(C2,"sig");k_ind = <>;for ns = 1:length(k) if cell2mat(k(i)) == 1 k_ind = ; endendping_id = k_ind+1;% find time of every pingping_time = time(ping_id);% Find variety of rows in ping, and also create document of depth and correlation% value (proxy for acoustic intensity)data = char(C2);ping_corr = <>;ping_depth = <>;for ns = 1:length(ping_id)-1 tmp = ping_id(i+1)-ping_id(i); shot for j = 1:tmp ping_depth(j,i) = str2num(data(ping_id(i)+j,1:5)); % depth ping_corr(j,i) = str2num(data(ping_id(i)+j,7:end)); % correlation value (acoustic intensity) finish endend ping_num = 1:1:length(ping_corr);%% produce ping median dataset (moving window). % do each ping document an typical signal native the bordering x variety of pings (if x is 2 then typical is 5 ping relocating window). X = 3;bin_depth = 0:0.05:8; % depths bins in which to median (change the middle value to adjust resolution (set currently at 0.05m v max depth 10m)bin_corr = zeros(length(bin_depth),length(ping_id-(x*2))); % create empty matrixcount = 1;for ns = x+1:length(bin_corr(1,:))-(x+2) tmp_depth = ping_depth(:,i-x:i+x); % discover all depth worths for x pings before and also after ping ns tmp_depth = tmp_depth(:); tmp_corr = ping_corr(:,i-x:i+x); % find all depth worths for x pings before and after ping ns tmp_corr = tmp_corr(:); tmp_bins = discretize(tmp_depth,bin_depth); % allocate data to depth bins because that ii = 1:length(bin_depth) bin_corr(ii, count) = nanmean(tmp_corr(tmp_bins == ii)); % calc bin median values for each ping home window if isnan(bin_corr(ii, count)) == 1 bin_corr(ii, count) = 0; end end counting = count+1;end
k_ind 28022×1 double,ping_corr 48×27630 double,ping_depth 48×27630 double,ping_id 28022×1 double,k 390908×1 cell,ping_num 1×27630 double,ping_time 28022×1 double,time 390908×1 dual ,tmp_bins 336×1 double,tmp_corr 336×1 double,tmp_depth 336×1 double,data 390908×37 char,bin_depth 1×161 double,bin_corr 161×28022 double.

See more: Skinner &Amp; Smith Funeral Home Dunn, Nc, Operant Conditioning (B

I have no idea exactly how to deal with this and preallocate for variety the exact same size as the pings due to the fact that for some reason its do a different size. Give thanks to you for your assist in advance, its lot appreciated.