Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Fill a matrix

Subject: Fill a matrix

From: Flavio Eripi

Date: 01 Aug, 2007 06:58:44

Message: 1 of 3

Is there any command to put the values outside the diagonal of a matrix?
For example if I want this matrix:
a= [1,5,5,5;
5,1,5,5;
5,5,1,5;
5,5,5,1];
Thank you

Subject: Re: Fill a matrix

From: us

Date: 01 Aug, 2007 07:36:38

Message: 2 of 3

Flavio Eripi:
<SNIP stitching numbers...

one of the many(!) solutions

     m=ones(4);
     m(~eye(size(m)))=5;
     m

us

Subject: Re: Fill a matrix

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 01 Aug, 2007 07:47:56

Message: 3 of 3

In article <f8pav4$pv1$1@fred.mathworks.com>,
Flavio Eripi <didad30@libero.it> wrote:
>Is there any command to put the values outside the diagonal of a matrix?
>For example if I want this matrix:
>a= [1,5,5,5;
>5,1,5,5;
>5,5,1,5;
>5,5,5,1];
>Thank you

V = 5;
a = magic(4);

cols = size(a,1);
a(~eye(cols)) = V;
--
  There are some ideas so wrong that only a very intelligent person
  could believe in them. -- George Orwell

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
eye us 01 Aug, 2007 03:40:20
diagonal us 01 Aug, 2007 03:40:20
code us 01 Aug, 2007 03:40:20
logical indexing us 01 Aug, 2007 03:40:20
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics