How do you link a function

3 ビュー (過去 30 日間)
Dameon Solestro
Dameon Solestro 2021 年 11 月 27 日
コメント済み: Walter Roberson 2021 年 12 月 9 日
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 件のコメント
Dameon Solestro
Dameon Solestro 2021 年 11 月 27 日
Path only gives an array of the x values, why is that??

サインインしてコメントする。

採用された回答

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 Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by