function to store image into dataset in matlab

To store an image into a dataset in MATLAB, you can follow these steps:

  1. Load the image you want to store into MATLAB using the imread function. For example:

    main.m
    img = imread('my_image.jpg');
    
    30 chars
    2 lines
  2. Create a dataset object using the dataset function. For example:

    main.m
    my_dataset = dataset();
    
    24 chars
    2 lines
  3. Add the image to the dataset using the addvars function. For example:

    main.m
    my_dataset = addvars(my_dataset, img);
    
    39 chars
    2 lines
  4. Name the variable using the VarNames property of the dataset. For example:

    main.m
    my_dataset.Properties.VarNames = {'my_image'};
    
    47 chars
    2 lines
  5. Save the dataset using the save command. For example:

    main.m
    save('my_dataset.mat', 'my_dataset');
    
    38 chars
    2 lines

The complete code would be:

main.m
img = imread('my_image.jpg');
my_dataset = dataset();
my_dataset = addvars(my_dataset, img);
my_dataset.Properties.VarNames = {'my_image'};
save('my_dataset.mat', 'my_dataset');
178 chars
6 lines

gistlibby LogSnag