필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Yun Inn
Yun Inn 2012년 7월 23일
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