problem with %d in MATLAB

Hi all;
I have image file having 01.dcm, 02.dcm, 03.dcm ... 22.dcm;
I want to read all these images with loop. How can I do it Please. I am just confuse with %d command as it can't recognize 01.dcm etc. it is just recognize 1.dcm, 2.dc, ...

 Respuesta aceptada

David Sanchez
David Sanchez el 1 de Ag. de 2013

0 votos

for k = 1:22
pic2read = strcat(num2str(k),'.dcm');
if k<10
pic2read = strcat('0',pic2read);
end
imread(pic2read);
end

5 comentarios

naila
naila el 1 de Ag. de 2013
Thank You Soooo much
naila
naila el 1 de Ag. de 2013
One more thing please!;
after doing some processing on those 22 images I want to save them in a single .mat file;
how it will be please! urgent
David Sanchez
David Sanchez el 1 de Ag. de 2013
use the save option.
doc save
will tell you all the saving option available.
It will be something like:
save('my_data_file.mat','your_images_array')
Jan
Jan el 1 de Ag. de 2013
Adding the '0' manually is a really inefficient solution. See Andrei's much nicer and faster sprintf method.

Iniciar sesión para comentar.

Más respuestas (1)

Andrei Bobrov
Andrei Bobrov el 1 de Ag. de 2013

2 votos

for k = 1:22, imread(sprintf('%02d.dcm',k)); end

1 comentario

Jan
Jan el 1 de Ag. de 2013
Editada: Jan el 1 de Ag. de 2013
+1. This is compact, direct, fast, not prone to typos.

Iniciar sesión para comentar.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by