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.
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Tony Mohan Varghese
2018-3-21
Before calling imread, use the following:
name = char(name); % assuming that name is a string array. This will convert to a character vector.
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!