Matlab: Can anyone explains this geometry file
3 views (last 30 days)
Show older comments
Fehaid Alshammari
on 21 Feb 2015
Answered: Chris McComb
on 21 Feb 2015
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');
0 Comments
Accepted Answer
Chris McComb
on 21 Feb 2015
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 Comments
More Answers (0)
See Also
Categories
Find more on Graphics Objects in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!