combination function using ndgrid
이전 댓글 표시
Hello,
I want to build a function which use ndgrid.
My function is
function [ varargout ] = comb( varargin )
[varargout]=ndgrid(varargin)
varargout=varargout(:);
disp([varargout])
end
My varargout are x1 x2 x3 and varargin are a,b,c where a=[1 2], b=[2 3] and c=[1 4]. Expected results are
1 2 1
2 2 1
1 3 1
2 3 1
1 2 4
2 2 4
1 3 4
2 3 4
but it seems like ndgrid doesn't work. What can i do? In command window works fine but as a function where I can put more varargins something is wrong.
채택된 답변
추가 답변 (2개)
Walter Roberson
2016년 5월 18일
[varargout{:}] = ndgrid(varargin{:});
댓글 수: 3
Nik Sam
2016년 5월 18일
Walter Roberson
2016년 5월 18일
function [ varargout ] = comb( varargin )
[varargout{1:nargout}] = ndgrid(varargin{:});
end
Nik Sam
2016년 5월 18일
Jos (10584)
2016년 5월 18일
0 개 추천
Take a look the content of ALLCOMB, which does exactly what you're after btw...
카테고리
도움말 센터 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!