How can I change values in my matrix according to conditions.

1 vue (au cours des 30 derniers jours)
Hannah Pickering
Hannah Pickering le 7 Fév 2017
I have a zeros(size,size) matrix that i want the values to change depending on my conditions. I have two conditions:
Support = FixedFixed or Support = PinnedPinned
When Support = FixedFixed my matrix coordinates should be
a(1,1) = 7;
a(1,2) = -4;
a(1,3) = 1;
a(size,size-2)=1;
a(size,size-1)=-4;
a(size,size)=7;
and when Support = PinnedPinned my matrix should be
a(1,1) = 5;
a(1,2) = -4;
a(1,3) = 1;
a(size,size-2)=1;
a(size,size-1)=-4;
a(size,size)=5;
can anyone help me code this?

Réponse acceptée

Chad Greene
Chad Greene le 7 Fév 2017
Try a switch.
switch SupportType
case 'PinnedPinned'
a(1,1) = 5;
a(1,2) = -4;
a(1,3) = 1;
a(size,size-2)=1;
a(size,size-1)=-4;
a(size,size)=5;
case 'FixedFixed'
a(1,1) = 7;
a(1,2) = -4;
a(1,3) = 1;
a(size,size-2)=1;
a(size,size-1)=-4;
a(size,size)=7;
end

Plus de réponses (0)

Catégories

En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by