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
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!