1
votes

I have a vector of values which i want to assign to a NxN matrix. The vector values correspond to the lower half of the matrix,but the matrix is symmetric.

The problem is that the vector values are not in order, but quite messed up and the only way I see this can happen is to assign the values by their corresponding coordinates in the matrix. These coordinates are known and available as different vectors.

So practically I have:

ROW=

 1    25    26    27    28    29    30     2    37    38 ...

COLUMN=

 1     1     1     1     1     1     1     2     2     2 ...

VECTOR=

1.2694   -0.1983    0.0574    0     0      0      0    1.2694    0      0 ...

...where the values stand for: k(1,1)=1.2694, k(25,1)=-0.1983,k(2,2)=0...etc

And the result I want, would be like: K=[

  1.2694      k(1,2)   k(1,3)   ...
     0         0     k(2,3)     ...    
 -0.0951   -0.0261    0.3019    ...    
     .         .         .      ...
     .         .         .      ... 
     .         .         .      ...                

I'm an occasional user of matlab,and definetily not a pro. That's the way I figured would work, since nothing else came out usefull.

If anyone could help, or has another idea for solving this problem,I would be gratefull.

Thanks in advance!

1

1 Answers

2
votes

You can use sub2ind to do this.

ind = sub2ind( size(K), R,C);

K(ind) = V;