0
function area = traparea(a,b,h)
%  traparea(a,b,h)   Computes the area of a trapezoid given
%                    the dimensions a, b and h, where a and b
%                    are the lengths of the parallel sides and
%                    h is the distance between these sides

%  Compute the area, but suppress printing of the result
area = 0.5*(a+b)*h;

This is just an example. I would like to know how to declare the values suppose a=5,b=4,h=8 in a seperate .m file and calling it into original function ie, traparea, using .in statement? for example .in a=5 like that Please help

1
  • Not clue what a ".in statement" is. You just call the function from the m-file: area = traparea(5,4,8);. Commented Feb 8, 2016 at 3:32

1 Answer 1

1

If I understand, you want to create a script file. Create a filename called "myscript.m" (pick any name you like), and place it in the same folder as "traparea.m" is located. Then, in the file "myscript.m", put the following:

a = 5;
b = 4;
h = 8;
result = traparea(a,b,h)   % this is one way to show the result
fprintf('my result is %f\n', result);  % this is another way to display the result

Once you have created the two files "myscript.m", and "traparea.m", you just type "myscript" at the command line.

Sign up to request clarification or add additional context in comments.

1 Comment

Much thankful to you. Much useful comment. If you don't mind shall I ask one more question? Is there any way to get the same result using internal data structures like in. ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.