Clear Filters
Clear Filters

resampling DEM using imresize in a for loop = cell array?

2 views (last 30 days)
I have a replicated, 20 'layer' DEM datacube 2380x1707x20 and want to iteratively decrease the grid resolution of each layer, while passing all outputs into a single object. It's a scaling exercise to compare resampling with smoothing.
imresize() function works well for decreasing the grid rez, and because each for loop output contains different dims I assume passing them into a single cell array is the way to go. But my approach and/or notation is off... help?
n = 1:1:20;
for i=1:n
out{i} = imresize(rast(:,:,i), 1/i, 'Method', 'box');
Cell contents assignment to a non-cell array object.

Accepted Answer

Sean de Wolski
Sean de Wolski on 2 May 2013
What is out before the loop starts?
You should preallocate it as a cell:
out = cell(3,1);
for ii = 1:3
out{ii} = imresize(rand(randi(100)),0.25);
  1 Comment
Sam on 3 May 2013
Thanks, Sean. Another for the karma bank.
out = cell(size((rast),3),1);
for i=1:size((rast),3)
out{i} = imresize(rast(:,:,i), 1/i, 'Method', 'box');

Sign in to comment.

More Answers (0)


Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!