Return function the same as the inputs.
显示 更早的评论
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 个评论
Kevin Chng
2018-10-11
Sorry, do you want your output same as input? I don't get it.
Stephen23
2018-10-11
@Bell: what size should the output structure be? What are the input values? Please give us some example input and expected output arrays.
Bell
2018-10-11
Guillaume
2018-10-11
"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.
采纳的回答
更多回答(1 个)
Guillaume
2018-10-11
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
类别
在 帮助中心 和 File Exchange 中查找有关 Spline Construction 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!