How do you link a function

1 view (last 30 days)
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
%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
%pos is the position of the prisoner with every step that they take.
%Every step accounts for one second.
pos= [x', y'];
hold on
%New function on another script called randomcheck
function [CoordinateGroup]=randomcheck(N,Np)
%[x,y] =get_xy_velocities(N);
hold on
for i=1:Np
hold on
% x_end=[vector(:,end)]
% y_end=[vector(:,end)]
% x_end(i)=[x(N,end)]
  1 Comment
Dameon Solestro
Dameon Solestro on 27 Nov 2021
Path only gives an array of the x values, why is that??

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 27 Nov 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)
You are only storing one of the outputs, which would correspond to x.
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 .
Walter Roberson
Walter Roberson on 9 Dec 2021
[x_end(j), y_end(j)] = CoordinateGroup(end);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!