Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Why do I get Subscript indices must either be real positive integers or logicals using this code? It appears that the error is in the last two lines. How can I solve this?

1 visualización (últimos 30 días)
clear
close all
%Set up movie
fig = figure;
%movien = avifile('Vicsekmovie','FPS',3,'compression','none')
J = 500; %Number of timestep t0 be used
UJ = 1; %Rate at which film is updated
t = 1/J; %Size of one time step
N = 2; %Number of individuals
e = 0.5; %e is eta the noise parameter, whose maximum value is 2*pi
BL = 5; %Body Length (in centimeters)
Prop_BL = 0.3; %It's a treshold value that indicates the minimun fraction of a half-length border of an elliptical fish with which a fish can interact with it.
xd = 1; %It´s a value in BL units that should vary between 0.5 and 4.
ai = 0.5*BL; %Half-Length of the focal fish
bi = 0.1*BL; %Half-Width of the focal fish
%The Influence Repulsion Zone has one completely elliptical borders. Completely beacuse fishes that are in the blind zone influences on focal fish besause of
%mecanosensorial signals detected by the focal fish 's lateral line.
aRepi = 1*BL ; %Length of the semi-major axis of the Repulsion Zone elliptical border
bRepi = 0.5*BL; %Length of the semi-minor axis of the Repulsion Zone elliptical border
%The Influence non-Repulsion Zone has two partially elliptical borders. Partially beacuse of the blind zone and non mecanosensorial zone assumed.
aInRepi = 4*BL; %Length of the semi-major axis of the Influence non-Repulsion Zone elliptical greater border
bInRepi = 3*BL; %Length of the semi-minor axis of the Influence non-Repulsion Zone elliptical greater border
L=40;%L is the size of the domain on which the individuals can move
%Falta considerar que las distancias entre los centros deba ser mayor o igual a 1 BL, para que no se sobrepongan las elipses, osea los cuerpos.
% x(i,j) gives the x coordinate of the Position of the elliptical ith fish center, at time j.
x=zeros(N,J+1);
x(:,1)=L*rand(N,1); %define initial x coordiantes of all individuals.
% y(i,j) gives the y coordinate of the Position of the elliptical ith fish center, at time j.
y=zeros(N,J+1);
y(:,1)=L*rand(N,1); %define initial y coordiantes of all individuals.
rapid=zeros(N,J+1);%Rapidez
rapid(:,1)=repmat(1*BL,N,1); % Rapidez de 1 BL per second for all the elliptical fishes at time "1".
% T(i,j) gives the angle with the x axis of the direction of motion of the ith fish at time j
T=zeros(N,J+1);
T(:,1)=2*pi*rand(N,1); %define initial direction of all individuals
% ox(i,j) gives the x coordinate of the orientation vector of the elliptical ith fish, at time j.
ox = zeros(N,J+1) ;
ox(:,1) = 2.*cos(T(:,1));
% oy(i,j) gives the y coordinate of the orientation vector of the elliptical ith fish, at time j.
oy = zeros(N,J+1);
oy(:,1) = 2.*sin(T(:,1));
%-------------------------------------------------------------------------------------------------------------------------------------------------------
%Variables, relations, functions, and conditions.
%--------------------------------------------------------------------
%--------------------------------------------------------------------
%Normalization of the Orientation vector of the focal fish "i" at time "j".
% oux(i,j) gives the x coordinate of the orientation unitary vector of the elliptical ith fish, at time j.
oux = zeros(N,J+1) ;
oux(:,1) = cos(T(:,1));
% OUy(i,j) gives the y coordinate of the orientation unitary vector of the elliptical ith fish, at time j.
ouy = zeros(N,J+1);
ouy(:,1) = sin(T(:,1));
oux(i,j) = cos(T(i,j));
ouy(i,j) = sin(T(i,j));

Respuestas (1)

Rik
Rik el 28 de Jul. de 2018
There are two big problems here: you did not format your code (by selecting your code and clicking the {}Code button), so it is very difficult to read. The other problem is that it seams you didn't define i and j yourself, so the default is used: the imaginary unit value. This is the reason why you should avoid them as indices, as they can lead to very strange behavior or difficult to debug code.
  1 comentario
Image Analyst
Image Analyst el 28 de Jul. de 2018
And one more error was not giving us the actual error (ALL the red text) that gives the line numbers and actual line of code that threw the error. Read this link

La pregunta está cerrada.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by