Attempted to access xx(1); index out of bounds because numel(xx)=0. & error in the line hist(val_i​n(:,i+2),h​ist_int1);

1 view (last 30 days)
I'm trying to eliminate spikes from a given set of values (and tried histograms). The bit of code before this seems to work but for context I've put in a bigger piece.
How do I get past the error?
min_val_in_crt=min(val_in(:,i));
max_val_in_crt=max(val_in(:,i));
med_val_in_crt=mean(val_in(:,i));
diff_in=max((max_val_in_crt-med_val_in_crt)/2, (med_val_in_crt-min_val_in_crt)/2);
for i=1:n-1
for p=1:size(val_in, 1)
if abs(val_in(p,i) - med_val_in_crt) < diff_in
val_in(p,i) = med_val_in_crt;
end
end
end
if isempty(next_fig3)
next_fig3=next_fig2+1;
end
figure(next_fig3);
for i=0:n-2
if rem(i,6)==0 figure(i/6+next_fig3);
next_fig3=i/6+next_fig2+1;
end
subplot(6,1,rem(i,6)+1);
plot(val_in(:,1),val_in(:,i+2),'r');
end
if isempty(next_fig4)
next_fig4=next_fig3+1;
end
figure(next_fig4);
for i=0:n-2
if rem(i,6)==0 figure(i/6+next_fig4);
next_fig5=i/6+next_fig4+1;
end
min_val_in_crt1=min(val_in(:,i+2));
max_val_in_crt1=max(val_in(:,i+2));
hist_int1=min_val_in_crt1:abs((max_val_in_crt1 -min_val_in_crt1)/gran):max_val_in_crt1;
subplot(6,1,rem(i,6)+1);
hist(val_in(:,i+2),hist_int1);
A1(:,i+1)=hist(val_in(:,i+2),hist_int1);
end

Answers (1)

Walter Roberson
Walter Roberson on 13 Dec 2015
hist_int1 might be empty. I suggest replacing
hist_int1=min_val_in_crt1:abs((max_val_in_crt1 -min_val_in_crt1)/gran):max_val_in_crt1;
with
hist_int1 = linspace(min_val_in_crt1, max_val_in_crt1abs, gran+1);
assuming that gran is a positive integer.

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!