Nested for loop still not working...
1 view (last 30 days)
Show older comments
Why will this work...
if true
% code
end
InstNames = fieldnames(HistData);
HistData.(InstNames{1}).(DataNames{1}) = SepHistData(:,1,1);
HistData.(InstNames{1}).(DataNames{2}) = SepHistData(:,2,1);
HistData.(InstNames{1}).(DataNames{3}) = SepHistData(:,3,1);
HistData.(InstNames{1}).(DataNames{4}) = SepHistData(:,4,1);
HistData.(InstNames{1}).(DataNames{5}) = SepHistData(:,5,1);
HistData.(InstNames{1}).(DataNames{6}) = SepHistData(:,6,1);
HistData.(InstNames{1}).(DataNames{7}) = SepHistData(:,7,1);
HistData.(InstNames{2}).(DataNames{1}) = SepHistData(:,1,2);
HistData.(InstNames{2}).(DataNames{2}) = SepHistData(:,2,2);
HistData.(InstNames{2}).(DataNames{3}) = SepHistData(:,3,2);
HistData.(InstNames{2}).(DataNames{4}) = SepHistData(:,4,2);
HistData.(InstNames{2}).(DataNames{5}) = SepHistData(:,5,2);
HistData.(InstNames{2}).(DataNames{6}) = SepHistData(:,6,2);
HistData.(InstNames{2}).(DataNames{7}) = SepHistData(:,7,2);
and this won't...
if true
% code
end
for k = length(InstNames)
for i = length(DataNames)
HistData.(InstNames{k}).(DataNames{i}) = SepHistData(:,i,k);
end
end
0 Comments
Accepted Answer
More Answers (1)
Sean de Wolski
on 18 Feb 2014
length(DataNames)
Will return something like seven I imagine.
Your for-loops will eventually want
SepHistData(7,7)
Which doesn't exist. This is not one of the options above
It seems to me like you want:
for k = 1:2
for i = 1:length(DataNames)
etc.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!