How to best read in specific number values from large quantity of dicom images

1 view (last 30 days)
I want to read in the value (100\250) from following unique lines in a large .ima file (can be read in notepad):
  • sAngio.sFlowArray.asElm[0].nVelocity = 100
  • sAngio.sFlowArray.asElm[0].nDir = 4
  • sAngio.sFlowArray.asElm[1].nVelocity = 100
  • sAngio.sFlowArray.asElm[1].nDir = 1
with:
fid = fopen ('filename')
expTP = fscanf(fid,'%[asElm[0].nVelocity =*^\n')
vencTP=regexp(expTP,%d,'match')
vencTP = str2num(vencTP)
expPE = fscanf(fid,'%[asElm[1].nVelocity =*^\n')
vencPE = regexp(expPE,%d,'match')
vencPE = str2num(vencPE)
Questions: 1) I have 560 .ima files all with 3xn.Velocity information each, is it the best way to 'fopen' all of them or is there a better way?
2) Its not working and I can't figure out why. Is my expr wrong for regexp fct?

Answers (1)

Walter Roberson
Walter Roberson on 14 Aug 2012
  2 Comments
su
su on 14 Aug 2012
Dear Walter,
Thanks for your link. For clarification and regards my second question:
So I have 560 files names similar as below:
  • 4D_FLOW_1.MR.4DFLOW_WIP680_SKYRAXQ.0015.0001.2012.06.28.17.36.57.625000.57146750.ima
  • 4D_FLOW_1.MR.4DFLOW_WIP680_SKYRAXQ.0015.0002.2012.06.28.17.36.57.625000.57146822.ima
In the very long text file I want to read in following lines, extracting the number at the end of (here) the line 1 and 3 :
  • sAngio.sFlowArray.asElm[0].nVelocity = 100
  • sAngio.sFlowArray.asElm[0].nDir = 4
  • sAngio.sFlowArray.asElm[1].nVelocity = 100
  • sAngio.sFlowArray.asElm[1].nDir = 1
With the link you send I changed my code to following:
for k = 1:lenght(fl_list)
file_name = ['*' num2str(k) '.ima'];
fid = fopen('*.ima');
textData = fread(fid);
velTPCode = 'asElm[0].nVelocity = * /n';
vencTP = regexp(velTPCode, '\d\d\d', 'match');
fclose(fid);
end
I want to have following information in the end for this example (but automated for the whole code, so I can apply it to all 560files):
>>vencTP
vencTP = 100
>>vencPE
vencPE = 100
su
su on 14 Aug 2012
I believe that in
velTPCode = 'asElm[0].nVelocity = * /n';
the * might be an issue, I want to include it in the line selection to extract the number value afterwards. How to do that?
Then I need to define that matlab should only read the number:
vencTP = regexp(velTPCode, '\d\d\d', 'match');
defined here with expr as '\d\d\d' (a 3degit number) but it comes up as empty, is that cause of the * above?

Sign in to comment.

Categories

Find more on Convert Image Type 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!