Return function the same as the inputs.
Mostrar comentarios más antiguos
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 comentarios
Kevin Chng
el 11 de Oct. de 2018
Sorry, do you want your output same as input? I don't get it.
Stephen23
el 11 de Oct. de 2018
@Bell: what size should the output structure be? What are the input values? Please give us some example input and expected output arrays.
Bell
el 11 de Oct. de 2018
Guillaume
el 11 de Oct. de 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.
Respuesta aceptada
Más respuestas (1)
Guillaume
el 11 de Oct. de 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
Categorías
Más información sobre Spline Construction en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!