Filter löschen
Filter löschen

Assigning names to variables automatically

2 Ansichten (letzte 30 Tage)
lreplo
lreplo am 10 Jul. 2015
Beantwortet: Walter Roberson am 11 Jul. 2015
I want to run a for loop that allows me to find an a range of months and years and give me the cell number they are in. But when I used find(), it doesnt assign it to a variable so I lose the cell number its in every time the for loop runs. So far I have this:
for i = 2009:2014
for j = [1 4 12]
tInd = find(y==i&m==j);
tInd_min = min(tInd)
tInd_max = max(tInd)
end
end
N = 36;
for k=1:N
for i = [2009 2010 2011 2012 2013 2014]
for j = [1 4 12]
my_field = strcat('v',num2str(k));
tInd = find(y==i&m==j);
tInd_min.(my_field) = min(tInd)
tInd_max.(my_field) = max(tInd)
end
end
end
Where the first one finds every index and spits it out. The second for loop assigns names to the variables wrong. Thanks in advance!
  1 Kommentar
Azzi Abdelmalek
Azzi Abdelmalek am 10 Jul. 2015
This is not clear, post some data with expected result

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 11 Jul. 2015
Don't do that.
for k=1:N
for i = [2009 2010 2011 2012 2013 2014]
for j = [1 4 12]
tInd = find(y==i&m==j);
tInd_min(k) = min(tInd)
tInd_max(k) = max(tInd)
end
end
end

Community Treasure Hunt

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

Start Hunting!

Translated by