Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Single, pairwise & triple perturbations

Subject: Single, pairwise & triple perturbations

From: Sam

Date: 23 Feb, 2012 03:09:20

Message: 1 of 3

I would like to create a matrix in MatLab from a vector called "N", in that "N" is [7 10 14 21] and M would be.
    
M=
[7 10 14 21
0 10 14 21
7 0 14 21
7 10 0 21
7 10 14 0
0 0 14 21
0 10 0 21
0 10 14 0
7 0 0 21
7 0 14 0
7 10 0 0
0 0 0 21
7 0 0 0]

How can I write a code that create this perturbation matrix "M" ?

Thanks,

Sam

Subject: Single, pairwise & triple perturbations

From: Roger Stafford

Date: 23 Feb, 2012 07:20:19

Message: 2 of 3

"Sam " <sameiwater@gmail.com> wrote in message <ji4al0$a8b$1@newscl01ah.mathworks.com>...
> I would like to create a matrix in MatLab from a vector called "N", in that "N" is [7 10 14 21] and M would be.
>
> M=
> [7 10 14 21
> 0 10 14 21
> 7 0 14 21
> 7 10 0 21
> 7 10 14 0
> 0 0 14 21
> 0 10 0 21
> 0 10 14 0
> 7 0 0 21
> 7 0 14 0
> 7 10 0 0
> 0 0 0 21
> 7 0 0 0]
- - - - - - - - -
  This goes only up to your "triples" but allows any length for N:

 n = length(N);
 M = zeros((n^3+5*n+6)/6,n); % Allocate space up to triples
 p = n:-1:1;
 s = 0;
 for k = n:-1:n-3 % Up to triples
  c = nchoosek(p,k);
  for m = 1:size(c,1)
   s = s + 1;
   M(s,c(m,:)) = N(c(m,:));
  end
 end

It includes all triples, though. Did you leave out [0 0 14 0] and [0 10 0 0] on purpose?

Roger Stafford

Subject: Single, pairwise & triple perturbations

From: Sam

Date: 23 Feb, 2012 15:32:27

Message: 3 of 3

"Roger Stafford" wrote in message <ji4pbi$mbs$1@newscl01ah.mathworks.com>...
> "Sam " <sameiwater@gmail.com> wrote in message <ji4al0$a8b$1@newscl01ah.mathworks.com>...
> > I would like to create a matrix in MatLab from a vector called "N", in that "N" is [7 10 14 21] and M would be.
> >
> > M=
> > [7 10 14 21
> > 0 10 14 21
> > 7 0 14 21
> > 7 10 0 21
> > 7 10 14 0
> > 0 0 14 21
> > 0 10 0 21
> > 0 10 14 0
> > 7 0 0 21
> > 7 0 14 0
> > 7 10 0 0
> > 0 0 0 21
> > 7 0 0 0]
> - - - - - - - - -
> This goes only up to your "triples" but allows any length for N:
>
> n = length(N);
> M = zeros((n^3+5*n+6)/6,n); % Allocate space up to triples
> p = n:-1:1;
> s = 0;
> for k = n:-1:n-3 % Up to triples
> c = nchoosek(p,k);
> for m = 1:size(c,1)
> s = s + 1;
> M(s,c(m,:)) = N(c(m,:));
> end
> end
>
> It includes all triples, though. Did you leave out [0 0 14 0] and [0 10 0 0] on purpose?
>
> Roger Stafford

It worked.

Thanks,

Sam

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us