필터 지우기
필터 지우기

Matlab: Can anyone explains this geometry file

조회 수: 1 (최근 30일)
Fehaid Alshammari
Fehaid Alshammari 2015년 2월 21일
답변: Chris McComb 2015년 2월 21일
I have this geometry file, which I don't understand. Can anyone explains what this line does?
case 1
bs = varargin{1};
boundary = [0,0.25,0.5,0.75;
0.25,0.5,0.75,1;
1,1,1,1;
0,0,0,0];
varargout{1} = boundary(:,bs);
I need to modify this file so that I replace the striaght lines, representing the edges by curved lines but first I need to understand what each line means .. This is the compelete m.file Thanks
function varargout = rechteckgeometrie(varargin)
length = 0.05315;
length2 = 0.07;
width = 0.575;
switch nargin
case 0
varargout{1} = 4;
case 1
bs = varargin{1};
boundary = [0,0.25,0.5,0.75;
0.25,0.5,0.75,1;
1,1,1,1;
0,0,0,0];
varargout{1} = boundary(:,bs);
case 2
if isempty(varargin{1}) && isempty(varargin{2})
varargout{1,2} = [];
else
bs = varargin{1};
s = varargin{2};
boundary = [0,width,width,0,0;
0,0,length2,length,0];
varargout{1} = (bs-4*s).*reshape(boundary(1,bs),size(bs))+...
(4*s+1-bs).*reshape(boundary(1,bs+1),size(bs));
varargout{2} = (bs-4*s).*reshape(boundary(2,bs),size(bs))+...
(4*s+1-bs).*reshape(boundary(2,bs+1),size(bs));
end
otherwise
disp('Wrong number of input arguments');
end
%-----------------
figure; clf;
pdegplot('rechteckgeometrie', 'edgeLabels', 'on');

채택된 답변

Chris McComb
Chris McComb 2015년 2월 21일
The snippet that you want to focus on is part of a switch statement. The variable nargin is a integer that tells you how many arguments are passed to the function, and varargin is a cell array that holds the arguments passed to the function. Similarly, varargout is a cell array that holds multiple outputs.
The switch statement has an argument of nargin (the number of arguments provided to the function. The line 'case 1' handles the case for which nargin=1. The next line bs=varargin{1} takes the first argument passed to the function (in this case the only one, since nargin=1) and stores it in bs. The next few lines defines a matrix, called boundary. Finally, the line 'varargout{1} = boundary(:,bs);' takes specific columns of boundary, and stores them in varargout.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by