0

this is my code

for k = 1 : 5
im = imread(sprintf('C:\1\%d.BMP',k));

%blablalba...

end

There are 5 BMP files in "C: \ 1 \"

The files are named 1.BMP, 2.BMP, 3.BMP, 4.BMP, and 5.BMP respectively

Use sprintf to import files of 1.BMP, 2.BMP ... 5.BMP respectively into imread

But there is an error.

error : demo_SR (line 5)

im = imread(sprintf('C:\1\%d.BMP',k));

Why do I get an error when I get k from 1 to 5 and write"%d"?

thanks you

3
  • 3
    You showed where the error is, not what the error is. Commented May 2, 2018 at 10:08
  • Those two lines are all the error messages. Commented May 2, 2018 at 10:12
  • 1
    If that is the case you have a bad installation of MATLAB, but I really really doubt it. Or you are not showing everything that is relevant Commented May 2, 2018 at 10:13

2 Answers 2

2

Try:

im = imread(sprintf('C:/1/%d.BMP',k));

MATLAB may interpret \ as a command for escaped characters.

Sign up to request clarification or add additional context in comments.

1 Comment

@ONION please consider going through all your questions and accepting the answers that helped you. Otherwise, people will stop answering your questions, as you are not following common courtesy
2

For the reason mentioned in @Ander Biguri's answer, you should either use a double backslash,

filename = sprintf('C:\\1\\%d.BMP',k);

or, more robust would be to let MATLAB insert the appropriate path separator by using fullfile,

filename = fullfile('C:','1',sprintf('%d.BMP',1));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.