How to update the image title automatically with the corresponding file name?

조회 수: 2 (최근 30일)
I have a file for eg: patient 101232-1, which is used to create an image and I have 100 files with tags: 101232\position-%d. How can I update the file name on the image title without inputting the patient number twice, I.e in dlm read line and image title line everytime i run the code. (please see the code below).
nfiles = input('Number of tissue files available: ');
for j = 1:nfiles
*DataC = dlmread(sprintf('%s%d%s','\\homes\Dec-30Days-2013\30-days-SI\128765(40db)\position-',j,'.txt'));*
*imageTitle=sprintf('Colour-128765-%d',j);*
Z=(Imagedata(Y,X));
figure('name',imageTitle,'numbertitle','off')
imagesc(SS*X,Depth,Z);
title(['Amplitude max = ' num2str(amp)]);

채택된 답변

Image Analyst
Image Analyst 2013년 1월 23일
That is not very robust code. You should really review the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F You create a filename, and just assume it exists - very bad practice. You should use exist() to check that it exists, or just use dir() before the loop to get only files that do exists. Then when you get the name you can use fullfile() and fileparts() to get the type of name you want - the full file name (folder plus base file name plus extension), or just the base filename. Then use sprintf() to construct a title/caption for your displayed image and use title() to send the caption to the GUI.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by