Вы находитесь на странице: 1из 5

1/17/2017 MATLABCentralShortcutforsymmetricmatrices

MATLABNewsgroup

Shortcutforsymmetricmatrices

Subject:Shortcutforsymmetricmatrices
From:Sasha
Date:14May,200910:37:37
Message:1of9
Replytothismessage
AddauthortoMyWatchList
Vieworiginalformat
Flagasspam

EverytimeIhaveasymmetricmatrixtoinput,Ifeelridiculouswhile
I'mtypingitinMatlabmanually.
Couldsomebodygivemeanideaorapieceofcodethatwouldcreatea
symmetricmatrixoutoftheuppertrianglememberssavedasavector?

IamabeginnerinMatlab,andanyadviceisgreatlyappreciated!
Thankyouallinadvance!

Subject:Shortcutforsymmetricmatrices
From:us
Date:14May,200910:46:01
Message:2of9
Replytothismessage
AddauthortoMyWatchList
Vieworiginalformat
Flagasspam

Sasha<sasa.tatar@gmail.com>wroteinmessage<d5d24296244a41d6986fac37042d37de@o14g2000vbo.googlegroups.com>...
>EverytimeIhaveasymmetricmatrixtoinput,Ifeelridiculouswhile
>I'mtypingitinMatlabmanually.
>Couldsomebodygivemeanideaorapieceofcodethatwouldcreatea
>symmetricmatrixoutoftheuppertrianglememberssavedasavector?
>
>IamabeginnerinMatlab,andanyadviceisgreatlyappreciated!
>Thankyouallinadvance!

showCSSMasmall,typicalinputandtheresultyouexpect...

us

Subject:Shortcutforsymmetricmatrices
From:BrunoLuong
Date:14May,200910:50:04
Message:3of9
Replytothismessage
AddauthortoMyWatchList
Vieworiginalformat
Flagasspam

Sasha<sasa.tatar@gmail.com>wroteinmessage<d5d24296244a41d6986fac37042d37de@o14g2000vbo.googlegroups.com>...
>EverytimeIhaveasymmetricmatrixtoinput,Ifeelridiculouswhile
>I'mtypingitinMatlabmanually.
>Couldsomebodygivemeanideaorapieceofcodethatwouldcreatea
>symmetricmatrixoutoftheuppertrianglememberssavedasavector?
>
>IamabeginnerinMatlab,andanyadviceisgreatlyappreciated!
>Thankyouallinadvance!

https://www.mathworks.com/matlabcentral/newsreader/view_thread/251343 1/5
1/17/2017 MATLABCentralShortcutforsymmetricmatrices

TakealookthispackageonFEX
http://www.mathworks.com/matlabcentral/fileexchange/23391

n=5
%Allocate
A=zeros(n)
i=itriu(size(A))%<thiscommandisfromthepackage

v=rand(size(i))%<inputsomewhere

%Assign
A(i)=v
%Symmetrize
Asym=A+triu(A,1).'

Bruno

Subject:Shortcutforsymmetricmatrices
From:Jos
Date:14May,200911:20:03
Message:4of9
Replytothismessage
AddauthortoMyWatchList
Vieworiginalformat
Flagasspam

Sasha<sasa.tatar@gmail.com>wroteinmessage<d5d24296244a41d6986fac37042d37de@o14g2000vbo.googlegroups.com>...
>EverytimeIhaveasymmetricmatrixtoinput,Ifeelridiculouswhile
>I'mtypingitinMatlabmanually.
>Couldsomebodygivemeanideaorapieceofcodethatwouldcreatea
>symmetricmatrixoutoftheuppertrianglememberssavedasavector?
>
>IamabeginnerinMatlab,andanyadviceisgreatlyappreciated!
>Thankyouallinadvance!

Hereissomethingforyoutochewon:

V=[111222132333]

M=triu(ones(3))
M(M==1)=V
M=M+tril(M.',1)

hth
Jos

Subject:Shortcutforsymmetricmatrices
From:Sasha
Date:18May,200912:13:29
Message:5of9
Replytothismessage
AddauthortoMyWatchList
Vieworiginalformat
Flagasspam

Thankyouguysverymuch!It'snobigdifferencewhenthematrixis
small,butit'satimesaverifit'sabigone!
Ilikedbothideasandwillbeusingtheminfuture!

Iwishtoexpressmygratitudeoncemore!

https://www.mathworks.com/matlabcentral/newsreader/view_thread/251343 2/5
1/17/2017 MATLABCentralShortcutforsymmetricmatrices
OnMay14,1:20pm,"Jos"<#10...@fileexchange.com>wrote:
>Sasha<sasa.ta...@gmail.com>wroteinmessage<d5d24296244a41d6986fac3=
7042d3...@o14g2000vbo.googlegroups.com>...
>>EverytimeIhaveasymmetricmatrixtoinput,Ifeelridiculouswhile
>>I'mtypingitinMatlabmanually.
>>Couldsomebodygivemeanideaorapieceofcodethatwouldcreatea
>>symmetricmatrixoutoftheuppertrianglememberssavedasavector?
>
>>IamabeginnerinMatlab,andanyadviceisgreatlyappreciated!
>>Thankyouallinadvance!
>
>Hereissomethingforyoutochewon:
>
>V=[111222132333]
>
>M=triu(ones(3))
>M(M==1)=V
>M=M+tril(M.',1)
>
>hth
>Jos

Subject:Shortcutforsymmetricmatrices
From:Raul
Date:12Nov,201016:47:05
Message:6of9
Replytothismessage
AddauthortoMyWatchList
Vieworiginalformat
Flagasspam

Sasha<sasa.tatar@gmail.com>wroteinmessage<d5d24296244a41d6986fac37042d37de@o14g2000vbo.googlegroups.com>...
>EverytimeIhaveasymmetricmatrixtoinput,Ifeelridiculouswhile
>I'mtypingitinMatlabmanually.
>Couldsomebodygivemeanideaorapieceofcodethatwouldcreatea
>symmetricmatrixoutoftheuppertrianglememberssavedasavector?
>
>IamabeginnerinMatlab,andanyadviceisgreatlyappreciated!
>Thankyouallinadvance!

Hi!,

Haveyouthoughtinthe"toeplitz"command?
E.g.

x=

12345

>>toeplitz(x)

ans=

12345
21234
32123
43212
54321

Subject:Shortcutforsymmetricmatrices
From:Sean
Date:12Nov,201016:58:04
Message:7of9

https://www.mathworks.com/matlabcentral/newsreader/view_thread/251343 3/5
1/17/2017 MATLABCentralShortcutforsymmetricmatrices
Replytothismessage
AddauthortoMyWatchList
Vieworiginalformat
Flagasspam

>Haveyouthoughtinthe"toeplitz"command?
>E.g.
>
>x=
>
>12345
>
>>>toeplitz(x)
>
>ans=
>
>12345
>21234
>32123
>43212
>54321

Althoughtoeplitzdoescreateasymmetricmatrix,it'snotusablewhentheentireupperorlowerportionofthematrixisdifferent.

TheOPwantedtobeabletomanuallyenteronesideandhaveit"symmetricize"itautomatically.Likethis:

A=[123045002]%uppertriangular

'B=symmetricize(A)'
B=[123245352]

Subject:Shortcutforsymmetricmatrices
From:PauloOliveira
Date:24Apr,201417:10:09
Message:8of9
Replytothismessage
AddauthortoMyWatchList
Vieworiginalformat
Flagasspam

Sasha<sasa.tatar@gmail.com>wroteinmessage<d5d24296244a41d6986fac37042d37de@o14g2000vbo.googlegroups.com>...
>EverytimeIhaveasymmetricmatrixtoinput,Ifeelridiculouswhile
>I'mtypingitinMatlabmanually.
>Couldsomebodygivemeanideaorapieceofcodethatwouldcreatea
>symmetricmatrixoutoftheuppertrianglememberssavedasavector?
>
>IamabeginnerinMatlab,andanyadviceisgreatlyappreciated!
>Thankyouallinadvance!

Iwouldsimplydothefollowing(assummingAisatriangularmatrix):

A=A+A'diag(diag(A))

Subject:Shortcutforsymmetricmatrices
From:StevenLord
Date:24Apr,201420:07:48
Message:9of9
Replytothismessage
AddauthortoMyWatchList
Vieworiginalformat
Flagasspam

https://www.mathworks.com/matlabcentral/newsreader/view_thread/251343 4/5
1/17/2017 MATLABCentralShortcutforsymmetricmatrices

"PauloOliveira"<poliveira.pub@gmail.com>wroteinmessage
news:ljbghh$sd1$1@newscl01ah.mathworks.com...
>Sasha<sasa.tatar@gmail.com>wroteinmessage
><d5d24296244a41d6986fac37042d37de@o14g2000vbo.googlegroups.com>...
>>EverytimeIhaveasymmetricmatrixtoinput,Ifeelridiculouswhile
>>I'mtypingitinMatlabmanually.
>>Couldsomebodygivemeanideaorapieceofcodethatwouldcreatea
>>symmetricmatrixoutoftheuppertrianglememberssavedasavector?
>>
>>IamabeginnerinMatlab,andanyadviceisgreatlyappreciated!
>>Thankyouallinadvance!
>
>Iwouldsimplydothefollowing(assummingAisatriangularmatrix):
>
>A=A+A'diag(diag(A))

Becareful.IfthediagonalofAcontainsnonfinitevalues,theywillbe
changedbythisoperation.CompareBandC:

A=magic(3)
A([1,5,9])=[Inf,Inf,NaN]
B=A+A'diag(diag(A))
C=triu(A,0)+triu(A,1).'

IfyouhaveStatisticsToolbox,theSQUAREFORMfunctionmayalsobeof
interest.


SteveLord
slord@mathworks.com
TocontactTechnicalSupportusetheContactUslinkon
http://www.mathworks.com

FeedforthisThread
AddtoMyWatchList

WhatisaWatchList?

TagsforthisThread
symmetry

Whataretags?
Atagislikeakeywordorcategorylabelassociatedwitheachthread.Tagsmakeiteasierforyoutofindthreadsofinterest.

Anyonecantagathread.Tagsarepublicandvisibletoeveryone.

19942017TheMathWorks,Inc.

https://www.mathworks.com/matlabcentral/newsreader/view_thread/251343 5/5

Вам также может понравиться