Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

For-loop: create new name and extract data

조회 수: 1 (최근 30일)
Jung
Jung 2014년 7월 23일
마감: MATLAB Answer Bot 2021년 8월 20일
So I have the following code below and am trying to use a 'for loop' to simplify. I am guessing have to use two sets of for loop but I am lost at the moment.
I have a dNPP which is matrix with 20 values.
NPP_2001 = [dNPP(1:1)];
NPP_2002 = [dNPP(2:2)];
NPP_2003 = [dNPP(3:3)];
NPP_2004 = [dNPP(4:4)];
NPP_2005 = [dNPP(5:5)];
NPP_2006 = [dNPP(6:6)];
NPP_2007 = [dNPP(7:7)];
NPP_2008 = [dNPP(8:8)];
NPP_2009 = [dNPP(9:9)];
NPP_2010 = [dNPP(10:10)];
I am thinking something along the line like this;
for k=2001:2010
for j=1:10
end
end
Any help would be appreciated

답변 (1개)

Joseph Cheng
Joseph Cheng 2014년 7월 23일
How do you get 20 values? as dNPP(n:n) is just dNPP(n). or does this continue to dNPP(20:20)?
Also I would way this isn't a simplify way of coding. I would suggest you use a single variable to represent these such as dNPP. or rename it as NPP_20XX. where NPP_20XX(10) would equal NPP_2010;.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by