Yes, and for larger arrays it might be beneficial to write in a loop:

a = rand(1000);
b = rand(1000,1000);
for i = 1:length(a)
    b[i,i] = b[i,i] + a[i];
end

Den tirsdag den 20. maj 2014 16.48.30 UTC+2 skrev paul analyst:
>
> b- not is zeros sometimes... 
> c= diagm(a)
> b=b+c.
> Thx
> Paul
>
> W dniu wtorek, 20 maja 2014 16:17:11 UTC+2 użytkownik Oliver Lylloff 
> napisał:
>>
>> Hi Paul, 
>>
>> if b is just zeros, then b = diagm(a).
>>
>> Best,
>> Oliver
>>
>>
>>
>> Den tirsdag den 20. maj 2014 15.04.33 UTC+2 skrev paul analyst:
>>>
>>> a=rand(5)
>>> b=zeros(5,5)
>>> how to apply a on diagonal b ?
>>> Paul
>>>
>>

Reply via email to