필터 지우기
필터 지우기

for in for loop

조회 수: 2 (최근 30일)
Marko Niko
Marko Niko 2023년 2월 7일
답변: Tushar Behera 2023년 2월 7일
I have the following code:
for i=1:time time = [1:1:999]
k=i;
for j=1:time
CE(i,k) = Ep(i) * Dp(j);
ETRF_p(i,k) = Mass_C2* Ep(i) * Dp(j);
k=k+1
end
end
Questions:
  1. What does the (i,k) mean? does the loop go through all values of i and k?
  2. How will the output look it?

채택된 답변

Tushar Behera
Tushar Behera 2023년 2월 7일
Hi Marko,
I believe you want to understand the code in your question and how the loop will work.
The code you have written will only loop through once. I believe that is not your desired behaviour.
The (i,k) in CE(i,k) and ETRF_p(i,k) represents a matrix index. The loop is supposed to construct a matrix by assigning values to each element of the matrix CE and ETRF_p. With your current code the output will be a single valued scalar.
It will be of great help if you provide little more context as of what you want to acheive with your code.
Regards,
Tushar

추가 답변 (0개)

카테고리

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