How to return answer in 8 columns of 2D matrices through division
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Jan
le 23 Juil 2012
Modifié(e) : Jan
le 23 Juil 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{:});
Plus de réponses (1)
Walter Roberson
le 30 Juil 2012
Please review the guide to tags and retag this question; see http://www.mathworks.co.uk/matlabcentral/answers/43073-a-guide-to-tags
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!