Loop only storing last run in nested for loop ... should be easy indixing easy for the experienced eye
Ältere Kommentare anzeigen
This is a bit complex to explain without an essay but in point form, I have:
A large matrix with two parameters for 6 heights I want to bin the data by one parameter and then store this data in a struct for each bin I then was to do this for each height
The data is arranged in the following order date x y x2 y2 x3 y3 ... where the different levels represent the parameters at different heights.
Here is the code I have thus for but the loop is making the structure of the struct (names etc) perfectly but not iteratively saving the data:
inpdata = tower_wind_GF_allyrs;
inpdata = inpdata(~any(isnan(inpdata),2),:);
inpdata = inpdata(~any(isinf(inpdata),2),:);
bin = 0:0.51444:40;%maxws;
names = strtrim(cellstr(num2str([1:(length(bin)-1)]'))');
names = strrep(strcat('bin',names),'.','');
names2 = {'height10m' 'height20m' 'height40m' 'height80m' 'height120m' 'height200m'};
ind = cell(6,(length(bin)-1));
for k = linspace(2,12,6)
for l = linspace(3,13,6)
for i = 1:(length(bin)-1)
for varname = 1:length(names2)
search = find(inpdata(:,k) >= bin(i) & inpdata(:,k) < bin(i+1));
ind{varname,i} = search
binned_wind_allyrs.(names2{1,varname}).(names{1,i}) = cell(1,(length(bin)-1));
binned_wind_allyrs.(names2{1,varname}).(names{1,i}) = [inpdata(ind{varname,i}(:,1),k),inpdata(ind{varname,i}(:,1),l)];
end
end
end
end
Would LOVE to figure this out. Thanks in advance
Akzeptierte Antwort
Weitere Antworten (1)
Iain
am 6 Aug. 2014
Simple answer is on the left hand side, you need to index with k, l, i and varname.
So, this ought to work:
binned_wind_allyrs(k,l,i,varname) = {[inpdata(ind{varname,i}(:,1),k),inpdata(ind{varname,i}(:,1),l)]};
But you might need
binned_wind_allyrs(k,l,i,varname, 1:(numel(bin)-1)) = {[inpdata(ind{varname,i}(:,1),k),inpdata(ind{varname,i}(:,1),l)]};
Kategorien
Mehr zu Structures finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!