필터 지우기
필터 지우기

How to define a variable form a value in for loop?

조회 수: 2 (최근 30일)
Osama Tabbakh
Osama Tabbakh 2019년 3월 17일
댓글: Stephen23 2019년 3월 17일
Hello everybodey,
I'm trying to define a variable name that depends on the value i in the loop for. That's my code:
for i = 1:2:40
Magnet_H_'num2str(i)' = readimage(Bilder,i);
figure;
imshow (Magnet_H_num2str(i))
end
How I can do it?
  댓글 수: 1
Stephen23
Stephen23 2019년 3월 17일
"I'm trying to define a variable name that depends on the value i in the loop for."
Dynamically defining or accessing variable names is one way that beginners force themselves into writing slow, complex, obfuscated code that is hard to debug. Read this to know why:
Indexing is neat, simple, easy to debug, and very efficient (unlike what you are trying to do). Indexing is what experienced MATLAB users use, and you should too.

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

답변 (1개)

Walter Roberson
Walter Roberson 2019년 3월 17일

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by