Мне нужна помощь, чтобы понять, как создать точку структуры.
Мне нужны два поля x и y, затем я хочу создать функцию, которая вычисляет расстояние между этими двумя точками.
Что у меня есть прямо сейчас:
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
%CHECK FOR VALID INPUT
if ~isfield(pointpair1,'x', pointpair2, 'x' ) || ~isfield(pointpair1,'y', 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
end
isfield
, вы используете ее неправильно. - person David   schedule 28.11.2014