I want to add number in given sequention

조회 수: 1 (최근 30일)
Kundan Prasad
Kundan Prasad 2021년 12월 8일
댓글: Kundan Prasad 2021년 12월 8일
I want to add 0.5 to x2, x5, x8, x11 and so on, without altering the value of x1, x3, x4, x6, x7, x9, x10. How to write code for such problem.
Thank you
0.709416 x1
0.709416 x2
0.709416 x3
0.707508 x4
0.707508 x5
0.707508 x6
0.705603 x7
0.705603 x8
0.705603 x9
0.703701 x10
0.703701 x11

채택된 답변

Voss
Voss 2021년 12월 8일
Referring to the code you posted in a comment:
v(2:3:end) = v(2:3:end)+0.05;

추가 답변 (1개)

KSSV
KSSV 2021년 12월 8일
You can extract indices using:
idx = 2:2:11 ;
  댓글 수: 2
Kundan Prasad
Kundan Prasad 2021년 12월 8일
This is my code. I want to keep u value same as it is, but the value of v should be change according to the previous statement.
clc
clear all
z = -7.5:0.01:7.5;
r = 40;
x = r - sqrt(r.^2 - (z.^2));
u= repelem(z, 3);
v= repelem(x,3);
for i=2:3:4503
j(i)= v(i)+0.05;
end
Rik
Rik 2021년 12월 8일
I'm a bit confused about what you actually want to do. It sounds like KSSV's suggestion is exactly what you need:
v(2:2:end)=v(2:2:end)+0.5;

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by