Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

save more than one image in a matfile

Asked by Elysi Cochin

Elysi Cochin (view profile)

on 4 Feb 2013
 i select an image from a folder and save it in a matfile..... then i load the matfile and display the image.....
    [filename pathname]=uigetfile('*.tif','Select An Image');
    inputImage=imread([pathname filename]);
    save imageMatfile inputImage

how to save more than one image in the same matfile(not all images in folder, but only those i want).......using these select statements is it possible???...... please do reply....

0 Comments

Elysi Cochin

Elysi Cochin (view profile)

Tags

Products

No products are associated with this question.

2 Answers

Answer by Walter Roberson

Walter Roberson (view profile)

on 4 Feb 2013
Accepted answer
for K = 1 : 10
  [filename pathname] = uigetfile('*.tif','Select An Image');
  inputImages{K} = imread(fullfile(pathname, filename));
end
save imageMatfile inputImages

http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F

4 Comments

Elysi Cochin

Elysi Cochin (view profile)

on 4 Feb 2013

will "append" work.... but sir i dont know the syntax for append.... please do reply sir.....

Jan Simon

Jan Simon (view profile)

on 4 Feb 2013

Whenever you do not know the syntax of a command, simply look at the documentation: help save and doc save.

Walter Roberson

Walter Roberson (view profile)

on 4 Feb 2013

If you have a new enough version of MATLAB, you can use matfile() to store additional array elements into an array stored in a .mat file.

You can use -append to store additional information into a .mat file, but you need to use a different variable name each time or else the existing content with that variable name will get overwritten.

Walter Roberson

Walter Roberson (view profile)

Answer by Azzi Abdelmalek

Azzi Abdelmalek (view profile)

on 4 Feb 2013

Saving your first image

im1={imread('first_image')}
save yourfile im1

Adding a new image

im1=imread('news_image')
im=load('yourfile')
im1=im.im1
im1{end+1}
save yourfile im1

4 Comments

Azzi Abdelmalek

Azzi Abdelmalek (view profile)

on 4 Feb 2013
im=load('yourfile')
im1=im.im1
for k=1:numel(im1)
 figure
 imshow(im1{k})
end
Elysi Cochin

Elysi Cochin (view profile)

on 4 Feb 2013

sir but i'm getting this error...

 ??? Cell contents reference from a non-cell array object.
 Error in ==> Untitled at 19
 imshow(im1{k})
Azzi Abdelmalek

Azzi Abdelmalek (view profile)

on 4 Feb 2013

Have you used?

im=load('yourfile')

and when saving the first image

 im1={imread('first_image')} 
Azzi Abdelmalek

Azzi Abdelmalek (view profile)

Contact us