필터 지우기
필터 지우기

variable name by cancatation in matlab

조회 수: 4 (최근 30일)
suvadip paul
suvadip paul 2014년 8월 7일
댓글: Image Analyst 2014년 8월 7일
I want to set
c1=1;
c2=4;
c3=9;
c4=16;
How to do this in the following way
for i=1:4
ci=i^2;
end
i.e i will vary to generate c1, c2, c3, c4 etc. from ci.

답변 (1개)

Image Analyst
Image Analyst 2014년 8월 7일
편집: Image Analyst 2014년 8월 7일
Don't use separate variables with different names. Use an array:
ci = [1:4].^2
If you really want to do it the for loop way, do this:
for k = 1 : 4
c(k) = k ^2;
end
  댓글 수: 2
suvadip paul
suvadip paul 2014년 8월 7일
Actually my actual problem is another one. I have just given an example. I just want to know how to change the variable name through a loop.

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

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by