Is it possible to report built-in functions and provide alternative for further releases?

5 ビュー (過去 30 日間)
I've found that a pretty basic built-in function nchoosek is far from ideal, and I have a way to improve it. Is it possible to report it somehow? Here's the code for nchoosek:
function c = nchoosek(v,k)
% the function, not really interesting, only the combs part
end
%----------------------------------------
function c = binCoef(n,k,classOut)
%a helper function, also not important
end
%----------------------------------------
function P = combs(v,m)
%COMBS All possible combinations.
% ...
v = v(:).'; % Make sure v is a row vector.
n = length(v);
if n == m
P = v;
elseif m == 1
P = v.';
else
P = [];
if m < n && m > 1
for k = 1:n-m+1
Q = combs(v(k+1:n),m-1);
P = [P; [v(ones(size(Q,1),1),k) Q]]; %#ok %<--- here's the problem
end
end
end
end
The problem is obviously at the %#ok line. That is not OK and runs really slow. We know the size prior, so preallocating is not a problem. My proposition is the following really simple algorithm for combs(1:n,m)
function [P] = combs(n, m)
%COMBS
vals = 1:m;
total = nchoosek(n, m);
P = zeros(total, m);
for I=1:total
P(I, :) = vals;
for M = m:-1:1
if vals(M)<n-m+M
vals(M) = vals(M)+1;
for MM = (M+1):m
vals(MM) = vals(M) + MM - M;
end
break;
end
end
end
end
Clearly this problem received some exposure by this question but I wonder if there's a way to do this directly.
  3 件のコメント
Lew
Lew 2018 年 8 月 25 日
Is this a bug??
Stephen23
Stephen23 2018 年 8 月 26 日
編集済み: Stephen23 2018 年 8 月 26 日
@Bodnar Levente: when you start the bug report ("service request") process one of the first options is "Technical Support: Installation, product help, bugs, suggestions, documentation errors, outages"
Clearly what you have is a "suggestion".

サインインしてコメントする。

採用された回答

Steven Lord
Steven Lord 2018 年 8 月 25 日
If you believe you've found a bug or have a suggestion for an enhancement request, please contact Technical Support using the Contact Us link in the upper-right corner of this page.
  1 件のコメント
Lew
Lew 2018 年 8 月 25 日
Thanks, I will. I've found the link you mentioned before, but I have a student license and it says for students that:
Technical support from MathWorks is available for activation, installation and bug-related issues.
So I just stopped there.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by