Return function the same as the inputs.
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Bell
am 11 Okt. 2018
Beantwortet: Guillaume
am 11 Okt. 2018
Hello every body,
I wrote a function to creat a curve and it worked fine and the function returns a vector of 1x1 size (see the attached image please). How to make this function return a vector nurbs of the same size as the input arguments?? Here is my function
function nurbs = nrbmak(coef,knots)
coefs = [0.0 1.5; 0.0 3.0];
knots = [0.0 0.0 1.0 1.0];
nurbs.form = 'B-NURBS';
nurbs.dim = 4;
np = size(coefs);
dim = np(1);
nurbs.number = np(2);
if (dim < 4)
nurbs.coefs = repmat([0.0 0.0 0.0 1.0]',[1 np(2)]);
nurbs.coefs(1:dim,:) = coefs;
else
nurbs.coefs = coefs;
end
nurbs.order = size(knots,2)-np(2);
knots = sort(knots);
nurbs.knots = (knots-knots(1))./(knots(end)-knots(1));
nrbctrlplot(nurbs);
end
6 Kommentare
Guillaume
am 11 Okt. 2018
"But it was not clear what I want to do. I'll delete the first question"
Then you edit the original question, not start a new question where we'll probably ask the same questions that have already been answered.
Akzeptierte Antwort
Steven Lord
am 11 Okt. 2018
Your nurbs variable is a scalar struct array. If you want it to be a non-scalar struct array (of size [1 126]) we can do that. But I think what you want is to use that scalar struct array to evaluate the non-uniform rational B-spline at a vector of points.
I would check the functions given in the Splines chapter in the documentation for Curve Fitting Toolbox work for your application, allowing you to create a spline without having to manually construct the struct yourself. If they do, and your goal is to evaluate the spline, see the Postprocessing section for some tools that may be useful to you.
0 Kommentare
Weitere Antworten (1)
Guillaume
am 11 Okt. 2018
Your function makes no sense. It takes two inputs, coef and knots, and the first thing it does is discard that knots input and replace it by a constant value. And if the coef vs coefs is a typo, it would also discard the coef input.
If coefs and knots are the default values that should be used if these aren't provided, then you need to check that they indeed have not been provided:
function nurbs = nrbmak(coefs, knots)
if nargin < 2 %knots not provided
knots = [0.0 0.0 1.0 1.0];
end
if nargin < 1 %coef not provided
coefs = [0.0 1.5; 0.0 3.0];
end
nurbs.form = 'B-NURBS';
nurbs.dim = 4;
nurbs.number = size(coefs, 2);
%simpler code than your if else:
nurb.coefs(end+1:3, :) = 0; %if matrix is less than 3 rows fill missing rows with 0
nurb.coefs(end+1:4, :) = 1; %if row 4 is not provided, fill with 1.
nurbs.order = size(knots,2)-np(2);
knots = sort(knots);
nurbs.knots = (knots-knots(1))./(knots(end)-knots(1));
nrbctrlplot(nurbs);
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Spline Construction finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!