How to return answer in 8 columns of 2D matrices through division

1 view (last 30 days)
I need to create 8 columns of matrices based on division of 2 separate sets of matrices. My code below:
PhysicalThickness=[0,5,10,15,20,25,30,35];
for i=1:length(PhysicalThickness)
h=num2str(i-1);
fileextension='.dcm';
filenameEN=strcat(XIOM0,h,fileextension);
filenameEX=strcat(XIO,h,fileextension);
[OPEN]=dicomread(filenameEN);
[data]=dicomread(filenameEX);
rTPS=data./OPEN;
end
%______________________________________________________________________%
PhysicalThickness=[0,5,10,15,20,25,30,35];
for j=1:length(PhysicalThickness)
h=num2str(j-1);
fileextension='.dcm';
EPIDfilenameEN=strcat(EPIDM0,h,fileextension);
EPIDfilenameEX=strcat(EPID,h,fileextension);
[OPEN]=dicomread(EPIDfilenameEN);
[data]=dicomread(EPIDfilenameEX);
rEPID=data./OPEN;
end
%____________________________________________________________________%
ratio=rTPS./rEPID;
rTPS and rEPID, both returned answer in 8 columns of PhysicalThickness (which is what I want). However, when I divide the product of the two (rTPS./rEPID), I get only 1 answer (belonging to the last PhysicalThickness).
How do I get the answer for all i/j (PhysicalThickness) in 8 columns instead of just one?

Accepted Answer

Jan
Jan on 23 Jul 2012
Edited: Jan on 23 Jul 2012
The problem appears, because you overwrite rTPS and rEPID in each iteration. The solution is to read both input and calculate the results inside the loop:
PhysicalThickness=[0,5,10,15,20,25,30,35];
ratio = cell(1, length(PhysicalThickness));
for i=1:length(PhysicalThickness)
h=num2str(i-1);
fileextension='.dcm';
filenameEN=strcat(XIOM0,h,fileextension);
filenameEX=strcat(XIO,h,fileextension);
OPEN=dicomread(filenameEN);
data=dicomread(filenameEX);
rTPS=data./OPEN;
%
EPIDfilenameEN=strcat(EPIDM0,h,fileextension);
EPIDfilenameEX=strcat(EPID,h,fileextension);
OPEN=dicomread(EPIDfilenameEN);
data=dicomread(EPIDfilenameEX);
rEPID=data./OPEN;
%
ratio{i} = rTPS./rEPID;
end
Or if you want to store the results as [m x n x r] array add this after the loop:
ratio = cat(3, ratio{:});

More Answers (1)

Walter Roberson
Walter Roberson on 30 Jul 2012
Please review the guide to tags and retag this question; see http://www.mathworks.co.uk/matlabcentral/answers/43073-a-guide-to-tags

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!