Home > Mobile >  How Can iterate Images from workspace in the function
How Can iterate Images from workspace in the function

Time:09-17

I have 20 Images saved in the .mat file and when I load these images to the workspace I want to iterate them in the function. The images have different names and different sizes. Anyone can help?

CodePudding user response:

Load your file. Call Matlab's "who(...)"-function which lists the variable names in the file. Use Matlab's "evalin(...)" function to store the variables' content into a cell array.

The final cell array "images" contains all your image data, regardless of the size of each individual image. Now you can iterate over this cell array as you see fit.

The following code should do the trick. You just need to replace your filename.

load('your_images.mat')
image_vars = who('-file', 'your_images.mat');
N_images = numel(image_vars);
images = cell(N_images, 1);
for ii = 1:N_images
    images{ii} = evalin('base', image_vars{ii});
end
  • Related