Multiple inputs into for loop
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Justine Schneider
le 28 Juil 2017
Commenté : Justine Schneider
le 31 Juil 2017
How do I tell MATLAB to run through the for loop with 3 varying variables?
The following is my current MATLAB code:
for numPixelSpinefromPhan = [2688.00 3619.00 4306.00 4009.00 5029.00 5224.00 4151.00 2518.00];
numPixelOneBonePlug = [679 992.6 1192 1708.25 2250.833333 3054.75 4811 7401.5];
numPixelAllTissuefromWaterPhan = [113180 106638 109623 99278 99981 103614 105711 94184];
%
for numofboneplugs = 1:4;
for CTnumofboneplugat120kV = 230;
%320 415 455 792 870];
CTnumoftissue = 0;
%
numPixelBonePlugs = (numofboneplugs*numPixelOneBonePlug);
numPixelSpine = numPixelSpinefromPhan;
numPixelBoneandSpine = numPixelBonePlugs + numPixelSpine;
numPixelSoftTissue = numPixelAllTissuefromWaterPhan - (numPixelBoneandSpine);
numPixelAll = numPixelBoneandSpine + numPixelSoftTissue;
%
TotalCTnumofboneplugat120kV = numofboneplugs*CTnumofboneplugat120kV*numPixelBonePlugs;
TotalCTnumofspineat120kV = CTnumofspineat120kV*numPixelSpine;
%
ct_bone = (TotalCTnumofboneplugat120kV*numPixelBonePlugs)+(TotalCTnumofspineat120kV*numPixelSpine);
ct_tissue = CTnumoftissue*numPixelSoftTissue;
ct_all = ct_bone + ct_tissue;
%
Percentage_Att_Bone(CTnumofboneplugat120kV) = (ct_bone * numPixelBoneandSpine) / (ct_all * numPixelAll);
end
end
end
0 commentaires
Réponse acceptée
James Tursa
le 28 Juil 2017
Modifié(e) : James Tursa
le 28 Juil 2017
E.g., to vary them at the same time
numPixelSpinefromPhan = [2688.00 3619.00 4306.00 4009.00 5029.00 5224.00 4151.00 2518.00];
numPixelOneBonePlug = [679 992.6 1192 1708.25 2250.833333 3054.75 4811 7401.5];
numPixelAllTissuefromWaterPhan = [113180 106638 109623 99278 99981 103614 105711 94184];
n = numel(numPixelSpinefromPhan);
for k=1:n
% Use numPixelSpinefromPhan(k), numPixelOneBonePlug(k), numPixelAllTissuefromWaterPhan(k)
end
4 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) 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!