MATLAB: Add a value in Matrix A from specific location in matrix B

matrix

Hello.
Lets say i have a A = 3000×1 matrix, and a matrix N = [49; 106; 198] where 49,106 and 198 is the locations of a variables in A. Then assign a value to that specific variable.
So i could assign the first value like A(49,1) = x and the second A(106,1) = y .
My problem is that i don't know the number of variables in N, and i don't know which spot in A i should assign the respective values to.
Thank you!

Best Answer

Well, if you really don't know the spot at which to assign you're stuck. But, if that's just poorly chosen words and you mean you don't know the syntax for the indirect assignment,
>> A=[1:10]';
>> N=[2 8 9];
>> Z=[44 21 pi];
>> A(N)=Z
A =
1.0000
44.0000
3.0000
4.0000
5.0000
6.0000
7.0000
21.0000
3.1416
10.0000
>>
QED, I think???