Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

For-loop: create new name and extract data

1 visualizzazione (ultimi 30 giorni)
Jung
Jung il 23 Lug 2014
Chiuso: MATLAB Answer Bot il 20 Ago 2021
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

Risposte (1)

Joseph Cheng
Joseph Cheng il 23 Lug 2014
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;.

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by