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

1 次查看(过去 30 天)
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?

采纳的回答

Jan
Jan 2012-7-23
编辑:Jan 2012-7-23
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{:});

更多回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by