Replace certain elements of vector with the values from another vector
Afficher commentaires plus anciens
Hi.
I could use some help here.
There is a zeros array, where I would like to replace some elements that have certain positions with the values from another vector. So, if I have:
A=[0 0 0 0 0] %Zeros vector
B=[5 6] %values
C=[2 5] %positions of elements in A that should receive a new value from B
How should I get a vector D=[0 5 0 0 6] ?
I appreciate your helping!
Réponse acceptée
Plus de réponses (1)
Olawale Oyewole
le 16 Juin 2023
1 vote
for i=1:3
x=[1 2 5];
y=zeros(1,3);
y(1:1:3)=1+log(x(i));
end
Please help replace each entry of y by 1+log(x(i)). That is I want y=[0 0 0] changed to y=[1+log(x(1)) 1+log(x(2)) 1+log(x(3))]
Catégories
En savoir plus sur Function Creation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!