How do I create a filename for TIFF's that change in every loop. Like P01.TIFF then P12.TIFF and so forth. I've set up this in strings but I think the single quotes are missing.
2 views (last 30 days)
Show older comments
I have 50 TIFF files that I need to read and operate on. The file names are like P01.TIFF, P12.TIFF, P23.TIFF, P34.TIFF and so forth all the way to P4950.TIFF. I want to open them in a loop. So I need to create a string that suffices for a file name. So I have
for image_no = 1:numi % Loop over number of images
L1 = image_no - 1; % Increment the z depth of the layer's front side
L2 = L1 + 1; % Increment the z depth of the layer's rear side
head = 'P'; % Header for each image file name
num1 = num2str(L1); % Convert L1 to string num1
num2 = num2str(L2); % Convert L2 to string num2
ext = '.tiff';
path = 'S:\LAO\Share\Smalley\FXR\Phase2\PSF\';
name = strcat(path,head,num1,num2,ext); % Create title with strings
PSF = imread(name);
I get the following error message
Error using imread>parse_inputs (line 450)
The file name or URL argument must be a character vector.
Error in imread (line 322)
[filename, fmt_s, extraArgs, was_cached_fmt_used] = parse_inputs(cached_fmt, varargin{:});
Error in Displaytiff (line 32)
PSF = imread(name);
Can anyone help? L1 and L2 each increment by 1 for each cycle through the loop. num1 and num2 are '0' and '1' for the first loop. name is "S:\LAO\Share\Smalley\FXR\Phase2\PSF\P01.tiff" but I think I'm missing single quotes or something. Thanks for your time. Paul
1 Comment
Answers (2)
Tony Mohan Varghese
on 21 Mar 2018
Before calling imread, use the following:
name = char(name); % assuming that name is a string array. This will convert to a character vector.
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!