4 views

Uploaded by Tim Acosta

combination function for matlab

save

- HW#2
- Expt_1Introduction to MATLAB
- Assignment Print 13
- Tobler 1979 CellularGeog
- Software Environment MATLAB
- Matlab Best
- Matlab Course
- Report FingerPrint
- Matlab TOC
- Matlab Compiler
- 1MCOMP0203.PDF
- More on functions in Matlab: Passing functions as arguments
- Slides 16.06 16.07 Matlab Simulink
- BEST LaTeX Mathmode
- Ele532 Matlabtutorial Full
- 29977312
- Matlab Tutorial for Systems and Control Theory
- Using MATLAB@-Sirnulink@Fo r Transient Analysis
- Fortran Arrays
- MATLAB_II
- CME Lab Session No5 (1)
- Basic Concepts in Matlab
- vibracion
- VR10-UG-ECE
- MfLab Keynote
- relnotes
- David.chen GEDC2010
- Modeling Ordinary
- drz-201409
- rfo-syllabus.pdf
- CE 14 4LQ Sample Exam1b
- CE 14 4LQ Formula Sheet
- CE 14 4LQ Sample Exam1a
- CE 14 Syllabus 2nd Sem 2010-2011
- intershiplecture.txt
- CE 156 Online LQ
- HK Temp Itinerary
- Lecture 1 Stresses
- Project Clarifications
- 02 Aggregates
- PS 1- REF.txt
- UPIS Lecture
- Introduction & Syllabus
- Problem 1 Graph
- Project Proposal
- Hotels in Naga
- Lecture 0 Orientation
- slides
- ES 13 Syllabus 1718A
- UPD_Faculty_Manual.pdf
- ES 13 THV PS-1
- Data Adjustment
- a100.pdf
- PS 1- REF.txt
- 1.1_Simple_Span_Beams.pdf
- Mathcad-in-Concrete-Structures-ACI-318-05-6th-Edition-CM.pdf
- CE 121 Class Policies
- ES 13 THV PS-1.pdf
- Data Adjustment 3.0
- Deed of Undertaking Form.pdf

You are on page 1of 3

)

% COMBN - all combinations of elements

% M = COMBN(V,N) returns all combinations of N elements of the elements in

% vector V. M has the size (length(V).^N)-by-N.

%

% [M,I] = COMBN(V,N) also returns the index matrix I so that M = V(I).

%

% V can be an array of numbers, cells or strings.

%

% Example:

%

M = COMBN([0 1],3) returns the 8-by-3 matrix:

%

0

0

0

%

0

0

1

%

0

1

0

%

0

1

1

%

...

%

1

1

1

%

% All elements in V are regarded as unique, so M = COMBN([2 2],3) returns

% a 8-by-3 matrix with all elements equal to 2.

%

% NB Matrix sizes increases exponentially at rate (n^N)*N.

%

% See also PERMS, NCHOOSEK

%

and ALLCOMB and PERMPOS on the File Exchange

%

%

%

%

**tested in Matlab R13, R14, 2010b
**

version 4.2 (apr 2011)

(c) Jos van der Geest

email: jos@jasen.nl

% History

% 1.1 updated help text

% 2.0 new faster algorithm

% 3.0 (aug 2006) implemented very fast algorithm

% 3.1 (may 2007) Improved algorithm Roger Stafford pointed out that for some val

ues, the floor

% operation on floating points, according to the IEEE 754 standard, could return

% erroneous values. His excellent solution was to add (1/2) to the values

% of A.

% 3.2 (may 2007) changed help and error messages slightly

% 4.0 (may 2008) again a faster implementation, based on ALLCOMB, suggested on t

he

%

newsgroup comp.soft-sys.matlab on May 7th 2008 by "Helper". It was

%

pointed out that COMBN(V,N) equals ALLCOMB(V,V,V...) (V repeated N

%

times), ALLCMOB being faster. Actually version 4 is an improvement

%

over version 1 ...

% 4.1 (jan 2010) removed call to FLIPLR, using refered indexing N:-1:1

%

(is faster, suggestion of Jan Simon, jan 2010), removed REPMAT, and

%

let NDGRID handle this

% 4.2 (apr 2011) corrrectly return a column vector for N = 1 (error pointed

%

out by Wilson).

error(nargchk(2,2,nargin)) ;

if isempty(V) || N == 0,

M = [] ;

IND = [] ;

elseif fix(N) ~= N || N < 1 || numel(N) ~= 1 ;

% nV = numel(V) .N) . end end % LOCAL FUNCTIONS function Y = local_allcomb(X.0 % nV = numel(V) .2 % % COMBN is very fast using a single matrix multiplication.'Second argument should be a positive integer') . % IND = fliplr(reshape(cat(ndims(IND{1}). % M = V(IND) . % return column vectors M = V(:) . % B = [nV. if only one output is requested % [IND{1:N}] = ndgrid(1:nV) . % concatenate into one matrix. else % indices requested IND = local_allcomb(1:numel(V). available on the File Exchange if N>1 % create a list of all possible combinations of N elements [Y{N:-1:1}] = ndgrid(X) .' . end % ========================================================================= % Previous algorithms % Version 3.N)) . % IND(:.nV^(N-i). % Version 2.nV) + 1 . else % speed depends on the number of output arguments if nargout<2. M = V(IND) .N) % See ALLCOMB. M = local_allcomb(V. reshape into 2D and flip columns Y = reshape(cat(N+1.IND{:}).N) . else % no combinations have to be made Y = X(:) .0 % for i = N:-1:1 % X = repmat(1:nV.^(1-N:0)] . % M = V(IND) . IND = (1:numel(V)).[]. % IND = rem(floor((A(:) * B(:)')). without any % explicit for-loops. % Combinations using for-loops .error('combn:negativeN'. % Version 1. % end % M = V(IND) .Y{:}).[]. % % use a math trick % A = [0:nV^N-1]+(1/2) . % % don waste space.nV^(i-1)). elseif N==1.i) = X(:).N) .

C(cc. for kk=1:nv. for jj=1:(nv^(ii-1)).ii) = V(kk) . cc = 1 . for mm=1:(nv^(N-ii)). cc = cc + 1 . C = zeros(nv^N.% % % % % % % % % % % % % % can be implemented in C or VB nv = length(V) .N) . % declaration for ii=1:N. end end end end .

- HW#2Uploaded byflounder33
- Expt_1Introduction to MATLABUploaded byNielsen Jose Marcelino
- Assignment Print 13Uploaded byDhrumil Gandhi
- Tobler 1979 CellularGeogUploaded byJose Northern Lights
- Software Environment MATLABUploaded byAvinash Hegde
- Matlab BestUploaded byFahim Uddin
- Matlab CourseUploaded byAzrin Kun
- Report FingerPrintUploaded byanurag0052
- Matlab TOCUploaded bygyuvaraj10
- Matlab CompilerUploaded bytrongngan
- 1MCOMP0203.PDFUploaded byteknikpembakaran2013
- More on functions in Matlab: Passing functions as argumentsUploaded bygantayat
- Slides 16.06 16.07 Matlab SimulinkUploaded bysokrateg
- BEST LaTeX MathmodeUploaded byTim_C
- Ele532 Matlabtutorial FullUploaded byudhayakumar_c
- 29977312Uploaded byshakir hussain
- Matlab Tutorial for Systems and Control TheoryUploaded byelfrich
- Using MATLAB@-Sirnulink@Fo r Transient AnalysisUploaded bySubhash Yadav
- Fortran ArraysUploaded byRam Kee
- MATLAB_IIUploaded byJin Hwan Jang
- CME Lab Session No5 (1)Uploaded byvvv
- Basic Concepts in MatlabUploaded byEt Linn
- vibracionUploaded byWilber Carbajal Sulca
- VR10-UG-ECEUploaded byMannanHarsha
- MfLab KeynoteUploaded byjaspreetsingh1243
- relnotesUploaded by2214311
- David.chen GEDC2010Uploaded byBOUZ2010
- Modeling OrdinaryUploaded byJojo Kaway
- drz-201409Uploaded byHakan Kaya
- rfo-syllabus.pdfUploaded byNithin Kiran

- CE 14 4LQ Sample Exam1bUploaded byTim Acosta
- CE 14 4LQ Formula SheetUploaded byTim Acosta
- CE 14 4LQ Sample Exam1aUploaded byTim Acosta
- CE 14 Syllabus 2nd Sem 2010-2011Uploaded byTim Acosta
- intershiplecture.txtUploaded byTim Acosta
- CE 156 Online LQUploaded byTim Acosta
- HK Temp ItineraryUploaded byTim Acosta
- Lecture 1 StressesUploaded byTim Acosta
- Project ClarificationsUploaded byTim Acosta
- 02 AggregatesUploaded byTim Acosta
- PS 1- REF.txtUploaded byTim Acosta
- UPIS LectureUploaded byTim Acosta
- Introduction & SyllabusUploaded byTim Acosta
- Problem 1 GraphUploaded byTim Acosta
- Project ProposalUploaded byTim Acosta
- Hotels in NagaUploaded byTim Acosta
- Lecture 0 OrientationUploaded byTim Acosta
- slidesUploaded byTim Acosta
- ES 13 Syllabus 1718AUploaded byTim Acosta
- UPD_Faculty_Manual.pdfUploaded byTim Acosta
- ES 13 THV PS-1Uploaded byTim Acosta
- Data AdjustmentUploaded byTim Acosta
- a100.pdfUploaded byTim Acosta
- PS 1- REF.txtUploaded byTim Acosta
- 1.1_Simple_Span_Beams.pdfUploaded byTim Acosta
- Mathcad-in-Concrete-Structures-ACI-318-05-6th-Edition-CM.pdfUploaded byTim Acosta
- CE 121 Class PoliciesUploaded byTim Acosta
- ES 13 THV PS-1.pdfUploaded byTim Acosta
- Data Adjustment 3.0Uploaded byTim Acosta
- Deed of Undertaking Form.pdfUploaded byTim Acosta