How do you link a function

3 visualizaciones (últimos 30 días)
Dameon Solestro
Dameon Solestro el 27 de Nov. de 2021
Comentada: Walter Roberson el 9 de Dic. de 2021
I would like to link these two functions together. Where N=3 and Np=4. So i expect 4 groups of 3x3 xy coordinates. I would like to plot each groupcoor vector on the same plot. This is not working.. Is there another way to do this?
function [x,y]=get_number(N)
%Where N is the total number of steps
x(1)=0;
y(1)=0;
%Where STP is the steps.
%The first step is the the coordinates (0,0)
for i=2:N
x(i)= rand()
y(i)= rand()
groupcoor=[x' y']
hold on
end
%pos is the position of the prisoner with every step that they take.
%Every step accounts for one second.
pos= [x', y'];
figure
plot(x',y');
hold on
end
%New function on another script called randomcheck
function [CoordinateGroup]=randomcheck(N,Np)
%[x,y] =get_xy_velocities(N);
hold on
for i=1:Np
Path=get_number(N)
CoordinateGroup(i)=Path
hold on
% x_end=[vector(:,end)]
% y_end=[vector(:,end)]
% x_end(i)=[x(N,end)]
%y_end(i)=[y(N,end)]
end
  1 comentario
Dameon Solestro
Dameon Solestro el 27 de Nov. de 2021
Path only gives an array of the x values, why is that??

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 27 de Nov. de 2021
function [x,y]=get_number(N)
get_number returns two 1 x floor(N(1)) outputs (unless N(1) < 1, in which case it returns two 1 x 1 outputs)
Path=get_number(N)
You are only storing one of the outputs, which would correspond to x.
CoordinateGroup(i)=Path
And you are expecting that 1 x N vector to fit within the single output location CoordinateGroup(i)
Perhaps you want to store into a cell array, CoordinateGroup{i} = Path after having constructed Path from the x and y outputs of get_number()
Where N=3 and Np=4. So i expect 4 groups of 3x3 xy coordinates
But your function get_number returns two 1 x N, not N x N or three 1 x N .
  11 comentarios
Dameon Solestro
Dameon Solestro el 27 de Nov. de 2021
but the first function, my outputs should be x,y (??) so then, how would y be kept?
Walter Roberson
Walter Roberson el 9 de Dic. de 2021
[x_end(j), y_end(j)] = CoordinateGroup(end);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by