why we use same parenthesis for function calling and array?

Illustration
Isaiah - 2020-12-14T09:57:06+00:00
Question: why we use same parenthesis for function calling and array?

a=fun(1,2) is used to call function fun and at the same time we use fun=randi(3,3) a=fun(1,2) to extract 1st row 2nd column of fun

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

function out = yourfun(a,b)
    m = randi(3,3);
    out = m(a,b);
end

or

 

function out = yourfun2(a,b)
    global m;
    out = m(a,b);
end

% example use function yourfun2

>> global m
>> m = randi(3,3);
>> out = yourfun2(1,2);


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!