views:

42

answers:

1

I need to make an image pyramid in matlab for one of my assignments. Though there are inbuilt methods to get the individual images in the pyramid, I am confused about how to store the handles to the images. (I don't have much experience with matlab)

Arrays don't work, since the images in the pyramid are of different size. I am looking for something like a list in .net, or arraylist in Java. In http://stackoverflow.com/questions/1413860/matlab-linked-list, they say that you can use the standard Java classes, but matlab hung when i tried to use java's arraylist. So, what is the best way to store a collection of heterogeneous data(or handles?) in matlab?

EDIT1 : The code which is not working:

im0 = imread('..\lenna-lg.jpg'); //im0 = 480*480*3 array
im1 = impyramid(im0,'reduce');  //im1 = 240*240*3 array
pyramid = [ im0, im1 ];  //Error : Error using ==> horzcat
                         //CAT arguments dimensions are not consistent.
+2  A: 

So with some further searching, i have found out what is called a cell, which basically seems to be a heterogeneous array. (http://stackoverflow.com/questions/2662964/cell-and-array-in-matlab). So the following code is working now

im0 = imread('..\lenna-lg.jpg'); //im0 = 480*480*3 array
im1 = impyramid(im0,'reduce');  //im1 = 240*240*3 array
cell = [ {im0}, {im1} ];  //cell = 1*2 cell
ans = cell{1};            //ans = 480*480*3 array

This seems to be a very convenient way to handle heterogeneous data. Is this the right way to go about this?

apoorv020
Either cell arrays or structures are the two best options for storing multiple data types in a single variable.
Edric
As @Edric suggests, cell arrays and structures should be on your reading list very soon. Later you should study containers and objects.
High Performance Mark
A couple of suggestions: 1) Don't use the name `cell` for a variable, since this will shadow the built-in function [CELL](http://www.mathworks.com/help/techdoc/ref/cell.html). 2) Your third line can be written in a more conventional way as `cellArray = {im0, im1};`.
gnovice

related questions