MATLAB: Calling variables from other functions

global variable function calling variables

This first function takes two vectors and generates another vector C from it. I then want to put these three vectors on a table using the second function, however I know variables created in functions are local to that function. How do I then put C into another function?
function [C] = myAND(A, B)
C = zeros(1, length(A))';
for i=1:length(A) % for i from 1 to the length of the vectors
x = A(i); % let x be the i-th element of A
y = B(i); % let y be the i-th element of B
if x == 1
if y == 1
C(i) = 1; % when x and y are both 1, C at index i is 1
end
else
C(i) = 0; % otherwise, C at index i is 0
end
end
end
second function:
function Untitled3(A,B,C)
fprintf(' | A | B | C |\n')
fprintf('======================\n')
disp([A,B,C])
fprintf('======================\n')
end

Best Answer

Simply write these command to a script or function:
C = myAND(A, B);
Untitled3(A, B, C);
Related Question