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?
0 件のコメント
採用された回答
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
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!