Vector element replacement by specified variables

1 Ansicht (letzte 30 Tage)
Olawale Oyewole
Olawale Oyewole am 16 Jun. 2023
Kommentiert: Voss am 17 Jun. 2023
I am currently having issues with this code. I want to replace each entry of a vector with specified values.
for i=1:3
x=[1 2 5];
y=zeros(1,3);
y(1:1:3)=1+log(x(i));
end
That is I want y=[0 0 0] replaced by y=[1+log(x(1)) 1+log(x(2)) 1+log(x(3))].
Thanks in anticipation.

Akzeptierte Antwort

Voss
Voss am 16 Jun. 2023
x = [1 2 5];
y = 1+log(x);
x,y
x = 1×3
1 2 5
y = 1×3
1.0000 1.6931 2.6094
  2 Kommentare
Olawale Oyewole
Olawale Oyewole am 16 Jun. 2023
Thanks for your response
Voss
Voss am 17 Jun. 2023
You're welcome! Any questions, let me know. Otherwise, please "Accept This Answer". Thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by