Passing Arrays to a SubFunction

2 次查看(过去 30 天)
Michael
Michael 2013-12-17
回答: Michael 2013-12-17
N = 20;
B = 3;
maxNum = 10;
xyz = zeros(N,B); % 20 x 3 % Current Run Array
xyz = maxNum * rand(N,3); % 20 x 3 % Random (x,y,z) positions
mySubFunct(xyz);
...
...
% Sub-Function - mySubFunct(inArray)
mySubFunct(inArray);
c = [0.0, 0.0, 0;...
0.0, 5.0, 0;...
0.0, 10.0, 0;...
5.0, 0.0, 0;...
5.0, 10.0, 0;...
10.0, 0.0, 0;...
10.0, 5.0, 0;...
10.0, 10.0, 0];
% 20x3 + 8x3 = 28x3
% Current Array + corners
abc = vertcat(inArray, c);
xs = abc(:,1);
ys = abc(:,2);
zs = abc(:,3);
abc = vertcat(inArray, c);
xs = abc(:,1);
ys = abc(:,2);
zs = abc(:,3);
plot3(xs,ys,zs,'.','MarkerSize',10);
ERROR:
Undefined function or variable 'mySubFunct'.
Error in myHomework (line 71)
mySubFunct();
What am I missing or doing wrong???

回答(3 个)

Matt J
Matt J 2013-12-17
编辑:Matt J 2013-12-17
Prior to where you define 'c', I think you meant to have
function mySubFunct(inArray);

Michael
Michael 2013-12-17
I added that, and I got the following ERROR:
Function definitions are not permitted in this context.
Do I need to declare the myHomework.m file as a function at the top?

Michael
Michael 2013-12-17
Added as first line of code:
Function myHomework
Then added:
function to the mySubFunct(inArray):
function mySubFunct(inArray)
and added end to the end of the mySubFunct & as the last line for myHomework:
end
end
AND IT WORKED!!! Danced around it for hours!!! Thanks!

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by