Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

To test your function, create a structure array containing the data for three pl

ID: 3841301 • Letter: T

Question

To test your function, create a structure array containing the data for three plots of three different types, and pass that structure array to your function The function should correctly plot all three data sets in three different figure windows. Define a structure point containing two fields x and y. The x field will contain the A-position of the point, and the y field will contain the y-position of the point. Then write a function dist3 that accepts two points and returns the distance between the two points on the Cartesian plane. Be sure to check the number of input arguments in your function. Write a function that will accept a structure as an argument, and return two cell arrays containing the names of the fields of that structure and the data types of each field. Be sure to check that the input argument is a structure, and generate an error message if it is not. Write a function that will accept a structure array of student as defined in this chapter, and calculate the final average of each one assuming that all exams have equal weighting.

Explanation / Answer

function [ out ] = pointDist3( pointpair1, pointpair2)
%FUNCTION pointDist3 takes in any two pairs of points and
% Calling sequence:
%   out = pointDist3(varargin)
%DEFINE VARIABLES
% minargs, maxargs = error checking variables
% pointpair1 = structure containing fields for point 1: x1 and y1
% pointpair2 = structure containing fields for point 2: x2 and y2
% out = structure containing field distance
minargs = 4;
maxargs=8;
nargchkin(minargs,maxargs);
%CHECK FOR VALID INPUT
if ~isfield(pointpair1,'x') || ~isfield(pointpair1,'y') || ...
    ~isfield(pointpair2,'x') || ~isfield(pointpair2,'y')

    error('Input argument does not contain fields "x" and "y" for both points');
else

      out = sqrt((pointpair1.x-pointpair2.x)^2+(pointpair1.y-pointpair2.y)^2);

end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote