Effacer les filtres
Effacer les filtres

problem with %d in MATLAB

8 vues (au cours des 30 derniers jours)
naila
naila le 1 Août 2013
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, ...

Réponse acceptée

David Sanchez
David Sanchez le 1 Août 2013
for k = 1:22
pic2read = strcat(num2str(k),'.dcm');
if k<10
pic2read = strcat('0',pic2read);
end
imread(pic2read);
end
  5 commentaires
Jan
Jan le 1 Août 2013
Adding the '0' manually is a really inefficient solution. See Andrei's much nicer and faster sprintf method.

Connectez-vous pour commenter.

Plus de réponses (1)

Andrei Bobrov
Andrei Bobrov le 1 Août 2013
for k = 1:22, imread(sprintf('%02d.dcm',k)); end
  1 commentaire
Jan
Jan le 1 Août 2013
Modifié(e) : Jan le 1 Août 2013
+1. This is compact, direct, fast, not prone to typos.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Historical Contests dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by