Compiling resampled data arrays using For loop

1 visualizzazione (ultimi 30 giorni)
I have six 20x1 cell arrays each containing a remote sensing variable resampled at 20 levels of resolution. I want to merge the six cells into a single cell array, by resolution. Thus, the output would be a cell containing twenty M x N x 6 arrays, where m and n are the same dims within each array.
There is a problem (or two) with how I am parsing outputs in my nested for loop. Thoughts?
vars = {'Cs' 'beta' 'As' 'TCI' 'TWI' 'hs'}
tmp = cell(size(dem)) % create supercell, one array per level of res
out = tmp;
tmp2 = size(vars) % create 6x1 subcells one array per variable
out2 = zeros(tmp2);
for i=1:numel(dem)
for j=1:numel(vars)
out{i} = out2(:,:,j)(Cs{i}, beta{i}, As{i}, TCI{i}, TWI{i}, hs{i});
end
end
Error: ()-indexing must appear last in an index expression.

Risposta accettata

Sam
Sam il 10 Mag 2013
Modificato: Sam il 10 Mag 2013
Self-answered, for posterity...
There are V variables stored in individual cells. Each cell contains R number of m x n arrays, where R represents a level of resolution. The goal is to create an R x 1 cell containing an n x m x V array at each level of R.
Assuming each R has the same corresponding dims across all V's (true here since they were outputs of the same resampling method) this is a simple concatenation of m x n arrays to m x n x V arrays. The new dims (3 instead of 2) are specified in the first argument of cat(). There is no need to extract and parse each R into a new object.
out = cell(20,1)
for i=1:numel(dem)
out{i} = cat(3, (Cs{i}, beta{i}, As{i}, TCI{i}, TWI{i}, hs{i});
end
Notably, the original script...
out{i} = out2(:,:,j)(Cs{i}, beta{i}, As{i}, TCI{i}, TWI{i}, hs{i})
... also indexes into an array that was already indexed into. MATLAB doesn't support this. See related post

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by