MATLAB: Won’t matlab recall the array ive just created in a function

functions

Hi,
I've written a function where output P is an array of numbers. Now i want to use P made in the function in another function, ie i want to recall P.
function P = poly_input(y)
% ————————————————————————-
% If no value is entered in the beginning
% ————————————————————————-
if (nargin ~= 1)
disp(' ');
y = input('Invalid, a single integer value must be entered: ');
while ~isscalar(y) || y ~= floor(y)
disp(' ');
y = input('Invalid, a single integer value must be entered: ');
end
end
% ————————————————————————-
% If a decimal is entered in the beginning
% ————————————————————————-
if ~isscalar(y) || y ~= floor(y)
while ~isscalar(y) || y ~= floor(y)
disp(' ');
y = input('Invalid, a single integer value must be entered: ');
end
end
disp(' ');
str1 = 'The polynomial will have order of ';
str2 = num2str(y);
disp([str1 str2 '.']);
% ————————————————————————-
% Inputting the coefficients
% ————————————————————————-
count = 0;
for orders = [0:1:y]
disp(' ')
str3 = 'What do you want the coefficient of x^';
str4 = ' to be; ';
alltogether = [str3 num2str(orders) str4];
count = count + 1;
Z(count) = input(alltogether);
end
P = int2str(Z);
P = str2num(P);
P
However, when i call for P in the command window MATLAB states that no value for P has been entered!?
Thanks

Best Answer

The array was created in the workspace of the function, but when you are at the command line, you are using the "base" workspace. http://www.mathworks.com/help/matlab/matlab_prog/base-and-function-workspaces.html
What you need to do in your case is, at the command line, use
P = poly_input();
Related Question