103k views
4 votes
Write a function separatethem that will receive one input argument which is a structure containing fields named length and width, and will return the two values separately. Here is an example of calling the function >> myrectangle = struct('length',33,'width',2); You just created a structure myrectangle with the above line of code. Now, if you send myrectangle into separatethem function, it should access the length and width fields and store it in output variables l and w (Again, no tips or tricks! do not overthink on this one. Just access the fields length and width from myrectangle input argument and store it in output variables l and w >> [l w] = separatethem(myrectangle) l = 33 w = 2

1 Answer

4 votes

Answer:

%seperatethem.m

%Creation and definition of functions

function [l w] = separatethem(myrectangle)

%Call the structure field length.

l = myrectangle.length(1);

%Call the structure field length.

w = myrectangle.width(1);

%Ending call function.

end

%trial of program

%Create a structure with two fields length and width.

myrectangle = struct('length',33,'width',2);

%Call the function separate them.

[l w] = separatethem(myrectangle)

User Fiskah
by
5.8k points