import multiple .tiff images into a structure, with fields of filename and file size, and a user inputed pixel size field in matlab

To import multiple .tiff images into a structure with fields of filename, file size, and user-inputted pixel size, you can use the following code:

main.m
% Prompt user to enter pixel size
pixelSize = input('Enter pixel size: ');

% Get file names in directory
files = dir('*.tiff');

% Initialize structure
imageStruct = struct('FileName', {}, 'FileSize', {}, 'PixelSize', {});

% Loop through files and get information
for i = 1:length(files)
    fileName = files(i).name;
    fileSize = files(i).bytes;
    
    % Store information in structure
    imageStruct(i).FileName = fileName;
    imageStruct(i).FileSize = fileSize;
    imageStruct(i).PixelSize = pixelSize;
end
519 chars
20 lines

This code prompts the user to enter the pixel size, gets the file names in the current directory that end in .tiff, initializes a structure with empty fields, loops through the files and gets the filename and file size, and stores the information in the structure with the user-inputted pixel size.

Note that this code assumes that all of the .tiff files are in the same directory as the script. If the files are in a different directory, you can modify the code to use the cd and dir functions to change to the directory and get the file names.

gistlibby LogSnag