필터 지우기
필터 지우기

Save loop variable naming problem

조회 수: 1 (최근 30일)
peter huang
peter huang 2022년 8월 30일
댓글: Stephen23 2022년 8월 31일
I want to save the answers in the loop for future use, I understand that I can use sprintf to batch store the data in the variables, but if I want to change my name with the loop, how can I do it?
ex.
for i = 1:10
k(i) = 2^i
end
k =
2 4 8 16 32 64 128 256 512 1024
I want to name the variables separately as
k1 = 2
k2 = 4
k3 = 8
....
k10 = 1024

답변 (1개)

Image Analyst
Image Analyst 2022년 8월 30일
Please don't do that. It's a bad idea. Why not do it? See the FAQ:
  댓글 수: 6
peter huang
peter huang 2022년 8월 31일
Great, I think this method is much better than eval Then I would like to ask how the variable I want to access today is not 1*n, but may have 68*n and then 20 years of data every year.

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

카테고리

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