Hi,I've tried everything to do prob 3 and 4 but I couldn't succeed.Can someone provide me the code for prob 2, 3,and 4 especially 3 and 4.Thankyou

2 次查看(过去 30 天)
This problem will test your variable handling skills.
(a) Write a function called hiddenSum that takes two inputs and returns the sum of the two inputs. Turn in a printout of the function.
(b) Write a script M-file called testHiddenSum.m that defines two variables x and y Assign some values to these variables. Call the function hiddenSum from within this script M-file and store the result in a local variable, z. Run the script M-file and turn in a printout with the value of z.
(c) Modify the function hiddenSum such that now it DOES NOT HAVE any output arguments. Now modify your script M-file such that it calls hiddenSum using x and y as inputs and assigns the result to the variable z. You will need to further modify your function file. Submit a printout of the new function and script files and command prompt results from running your script M-file.
(d) Now modify your function hiddenSum such that it DOES NOT HAVE any input OR output arguments. Modify your script M-file such that it calls hiddenSum using x and y as inputs, and stores the result in the variable z. You will need to further modify your function file. Submit a printout of the new function and script files, and the command prompt results from running your script M-file.
  11 个评论
per isakson
per isakson 2021-9-2
Promise not to use this
%%
x = 1;
y = 2;
%%
hiddenSumC( x, y );
%%
hiddenSumD();
%%
disp( [zC,zD] )
3 3
%%
function hiddenSumC( x, y )
z = x + y;
assignin( 'base', "zC", z );
end
function hiddenSumD()
x = evalin( 'base', "x" );
y = evalin( 'base', "y" );
z = x + y;
assignin( 'base', "zD", z );
end
And btw, I've forgotten there is a command, global. I never use it.
ajeet sahu
ajeet sahu 2021-9-2
Haha promised. This code actually does the complete job for prob 'c' and 'd'.Matlab never disappoint us.Thankyou very much for complete answer.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by