column index out of bounds; value 17 out of bound 16
Show older comments
Hello,
I am working on a program, it is not finish yet, but I am completely stuck by a error, I really don't know why this error occurs. This error is : column index out of bounds; value 17 out of bound 16
Could you please help me ? Thank you in advance, this is the program :
clear all
close all
% System variables
teta_hex=0;
phi_hex=0;
p_hex=0;
d=0;
rl=0;
N=1;
poss=0;
m1=1;
m2=1;
m3=1;
n=input('Mirrors number : ');
diam=input('What is the diameter of the mirrors used : ');
for g=1:n
% Enter the coordonnates of all the hexagonal mirrors
x_hex(g)=input('Enter x_hex for the hexagonal mirrors : ');
y_hex(g)=input('Enter y_hex for the hexagonal mirrors : ');
end
for g=1:n
% Enter the coordonates of the hexagonal mirrors target
x_f(g)=input('Enter x_f for the target mirrors : ');
% This program just works for y_f(g)=0
end
% Step to change angles and distances
step_angle=input('Enter the step of the angles of mirrors in degrees : ');
step_distance=input('Enter the step of the distance of mirrors in micrometers : ');
nbr_angle=90/step_angle
nbr_dist=100/step_distance
% Mirrors variation
for i=1:n
% Variation of the angle teta of the mirrors
for j=1:(nbr_angle)
% Variation of the angle phi of the mirrors
for k=1:(nbr_angle)
% p_hex variation
for l=1:(nbr_dist)
% rl variation
for m=1:(nbr_dist)
% d variation
for o=1:(nbr_dist)
% Calcul of teta_lens, s, r, phi_lens, psi_lens and xi_lens
r=rl+p_hex;
psi_lens=2*teta_hex;
xi_lens=2*phi_hex;
x_lens=r*sind(xi_lens);
y_lens=r*sind(psi_lens)+x_hex(i);
z_lens=r*cosd(psi_lens);
%if (i>1 && x_lens==x_lensN(i-1)+diam)
% Save all possibilities, N is the nomber of possibilities done
if (r*sind(psi_lens)+y_hex(i))~=0 && (r*sind(xi_lens)+x_hex(i))~=0 && (x_hex(i)+(r*sind(xi_lens))-x_f(i))~=0 && i==1
poss=functioncalculs(x_f, x_hex, y_hex, teta_hex, phi_hex, p_hex, xi_lens, psi_lens, x_lens, y_lens, z_lens, rl, r, d, i, N);
matriceposs(:,N) = poss;
coord(N,i)=poss(15)
N=N+1;
m1=m1+1;
d=d+step_distance;
elseif (r*sind(psi_lens)+y_hex(i))~=0 && (r*sind(xi_lens)+x_hex(i))~=0 && (x_hex(i)+(r*sind(xi_lens))-x_f(i))~=0
for j=1:N-1 % Try for every x coordonates of mirrors 1
if matriceposs(11,j)==i-1 && matriceposs(12,j)-(100)<=x_lens && x_lens<=matriceposs(12,j)+(100) && i~=1
poss=functioncalculs(x_f, x_hex, y_hex, teta_hex, phi_hex, p_hex, xi_lens, psi_lens, x_lens, y_lens, z_lens, rl, r, d, i, N);
matriceposs(:,m)=poss
N=N+1
if i==2
coord(N-m1,i)=poss(15);
m2=m2+1
else
coord(N-m2,i)=poss(15);
m3=m3+1
end
d=d+step_distance;
else
%printf('Pas entrée dans le if\n');
end
end
else
% Increment
d=d+step_distance;
end
end
rl=rl+step_distance;
end
p_hex=p_hex+step_distance;
end
phi_hex=(xi_lens/2)+step_angle;
end
teta_hex=(psi_lens/2)+step_angle;
end
end
Nfinal=N-1
2 Comments
Guillaume
on 22 Jun 2015
When posting an error, post the entire error message. Everything in red. Missing from your post is the most important bit: the line where the error occurs.
Note that I doubt anybody is going to try to understand all the code you've posted, so only post the relevant portion of it.
Adam
on 22 Jun 2015
Just as an observation, there are very few cases (if any) I imagine where programming 7 layers deep in nested for loops is a good idea. It is not too surprising that you start to get these kind of errors because the possibilities for such things occurring are all over the code.
Answers (0)
Categories
Find more on Programming 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!