MATLAB: How to change values in the matrix according to conditions.

matrix

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?

Best Answer

  • 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