Passing Arrays to a SubFunction

2 views (last 30 days)
Michael
Michael on 17 Dec 2013
Answered: Michael on 17 Dec 2013
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???

Answers (3)

Matt J
Matt J on 17 Dec 2013
Edited: Matt J on 17 Dec 2013
Prior to where you define 'c', I think you meant to have
function mySubFunct(inArray);

Michael
Michael on 17 Dec 2013
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 on 17 Dec 2013
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!

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!