How do you link a function

2 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2021-11-27
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 个评论
Dameon Solestro
Dameon Solestro 2021-11-27
but the first function, my outputs should be x,y (??) so then, how would y be kept?
Walter Roberson
Walter Roberson 2021-12-9
[x_end(j), y_end(j)] = CoordinateGroup(end);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by