imread is not accepting my file name string
Show older comments
I have attached my test script and sample image. I'm trying to create a Matlab script to build image file names and open image files with imread. Here is my simple code that I CAN'T get to work. I don't see what I am doing wrong. I get an error saying Matlab imread needs an input file string - but I AM giving it a file string. What am I doing wrong?
If I type in the file name directly it works, like this:
inputImage = imread(RGB0.png);
But my script below does not work, why?
%---------- begin script here
clear;
f= 0 ;
inFileStr = 'xxxxxxxxxxxx';
finishedFileStr = 'yyyyyyyyyyyy';
% these test fprints indicate that I can create a valid file name.
inFileStr = "RGB%d.png";
finishedFileStr = sprintf(inFileStr, f);
fprintf('finished string = ');
fprintf(finishedFileStr);
fprintf('\n');
% So why does the next line NOT work, I get the error:
% "The file name or URL argument must be a character vector."
inputImage=imread(finishedFileStr);
% ---------- end script here
Answers (1)
Walter Roberson
on 6 Jul 2017
Change
inFileStr = "RGB%d.png";
to
inFileStr = 'RGB%d.png';
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!