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