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:
Fitting N(N-1) points on an NxN matrix

Subject: Fitting N(N-1) points on an NxN matrix

From: Vic

Date: 1 Dec, 2012 14:02:07

Message: 1 of 6

Suppose I have an N(N-1) vector that corresponds to each non-diagonal entry of an NxN matrix. Is there anyway that I can encode that onto my matrix?

i.e. For n=3, given [ 2 3 4 5 6 7 ] we obtain

[0 4 6 ;
 2 0 7 ;
 3 5 0]?

Subject: Fitting N(N-1) points on an NxN matrix

From: Vic

Date: 1 Dec, 2012 14:07:08

Message: 2 of 6

Sorry this was meant to be in the "Answers" section....

"Vic" wrote in message <k9d2ku$dal$1@newscl01ah.mathworks.com>...
> Suppose I have an N(N-1) vector that corresponds to each non-diagonal entry of an NxN matrix. Is there anyway that I can encode that onto my matrix?
>
> i.e. For n=3, given [ 2 3 4 5 6 7 ] we obtain
>
> [0 4 6 ;
> 2 0 7 ;
> 3 5 0]?

Subject: Fitting N(N-1) points on an NxN matrix

From: Bruno Luong

Date: 1 Dec, 2012 14:17:15

Message: 3 of 6

"Vic" wrote in message <k9d2uc$e4h$1@newscl01ah.mathworks.com>...
> Sorry this was meant to be in the "Answers" section....
>
> "Vic" wrote in message <k9d2ku$dal$1@newscl01ah.mathworks.com>...
> > Suppose I have an N(N-1) vector that corresponds to each non-diagonal entry of an NxN matrix. Is there anyway that I can encode that onto my matrix?
> >
> > i.e. For n=3, given [ 2 3 4 5 6 7 ] we obtain
> >
> > [0 4 6 ;
> > 2 0 7 ;
> > 3 5 0]?

n = 3;
x = [ 2 3 4 5 6 7 ]

A = zeros(n);
A(setdiff(1:n^2,1:n+1:n^2)) = x

% Bruno

Subject: Fitting N(N-1) points on an NxN matrix

From: Vic

Date: 1 Dec, 2012 14:30:08

Message: 4 of 6

Thanks!


"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <k9d3hb$fnh$1@newscl01ah.mathworks.com>...
> "Vic" wrote in message <k9d2uc$e4h$1@newscl01ah.mathworks.com>...
> > Sorry this was meant to be in the "Answers" section....
> >
> > "Vic" wrote in message <k9d2ku$dal$1@newscl01ah.mathworks.com>...
> > > Suppose I have an N(N-1) vector that corresponds to each non-diagonal entry of an NxN matrix. Is there anyway that I can encode that onto my matrix?
> > >
> > > i.e. For n=3, given [ 2 3 4 5 6 7 ] we obtain
> > >
> > > [0 4 6 ;
> > > 2 0 7 ;
> > > 3 5 0]?
>
> n = 3;
> x = [ 2 3 4 5 6 7 ]
>
> A = zeros(n);
> A(setdiff(1:n^2,1:n+1:n^2)) = x
>
> % Bruno

Subject: Fitting N(N-1) points on an NxN matrix

From: Bruno Luong

Date: 1 Dec, 2012 14:54:07

Message: 5 of 6

Another way

A = zeros(n);
A(~diag(true(1,n))) = x

% Bruno

Subject: Fitting N(N-1) points on an NxN matrix

From: Roger Stafford

Date: 2 Dec, 2012 00:02:08

Message: 6 of 6

"Vic" wrote in message <k9d2ku$dal$1@newscl01ah.mathworks.com>...
> Suppose I have an N(N-1) vector that corresponds to each non-diagonal entry of an NxN matrix. Is there anyway that I can encode that onto my matrix?
- - - - - - - - - -
  Bruno's are better, but for the sake of variety and to show the possibilities with 'floor' here's a third way:

 A = zeros(n);
 A(floor(((n+1)*(1:n*(n-1))-1)/n)+1) = x;

Roger Stafford

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