필터 지우기
필터 지우기

How save the array?

조회 수: 4 (최근 30일)
ANANTA BIJOY BHADRA
ANANTA BIJOY BHADRA 2023년 3월 29일
댓글: Andres Montes 2023년 3월 29일
I have an array satring from 0.1 to 1 with 0.1 difference. I have to use it in foor loop. It is required that ra has to be in the below format.
for ra=0.1:0.1:1
%do something
end
howover, the value of ra is also have to be stored in a different array. Lets say the array is raz. How can I store the value of ra with each iteration in raz? I hope i have been able to explain the question

답변 (1개)

Andres Montes
Andres Montes 2023년 3월 29일
Hi, you can first store the raz and then use it in a for:
raz=(0.1:0.1:1)
raz = 1×10
0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000
for ra=raz(1):raz(end)
%Do something
end
In this way you'll have both, the for and the variable
  댓글 수: 1
Andres Montes
Andres Montes 2023년 3월 29일
Another thing you can do is declare the variable raz, and then use positions in the for instead of the actual numbers
raz=(0.1:0.1:1)
for i=1:length(raz)
ra=raz(i);
%Do something
end
In this way you can have your vector raz and utilize the value you need by calling a speific element of the vector

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by