How do i store all the results from a set of 'for' loops, not just the results from the last iteration?
1 次查看(过去 30 天)
显示 更早的评论
When i run my script each time my for loop runs it overwrites the results of the previous itteration, is there a way to have it store all the results from each iteration? Here is the code in question.
clear
img = imread('cameraman.tif');
for Mean = 0.01:0.01:0.1
V=0.01;
noise = imnoise(img,'gaussian',Mean,V);
NoisePower = V*numel(img);
NPowerInt = fix(NoisePower);
[peaksnr, snr] = psnr(noise,img);
nsr = 1/snr;
for hsize = 3:1:26
for sigma = 0.5:0.5:5
PSF = fspecial('gaussian',hsize,sigma);
NoiseyBlurred = imfilter(noise,PSF,'replicate','same','conv');
BlindDeconv = deconvblind(NoiseyBlurred,PSF,15);
LucyFilter = deconvlucy(NoiseyBlurred,PSF,15);
WNRFilter = deconvwnr(NoiseyBlurred,PSF,nsr);
RegularFilter = deconvreg(NoiseyBlurred,PSF,snr);
PSNRBlurred = psnr(NoiseyBlurred,img);
PSNRBlind = psnr(BlindDeconv,img);
PSNRLucy = psnr(LucyFilter,img);
PSNRWNR = psnr(WNRFilter,img);
PSNRReg = psnr(RegularFilter,img);
Blur(hsize)= (40-PSNRBlurred)/40;
Blind(hsize)=PSNRBlind;
Lucy(hsize)=PSNRLucy;
WNR(hsize)=PSNRWNR;
Reg(hsize)=PSNRReg;
end
end
end
I can't store the data based off 'Mean' instead of hsize as it gives the error Subscript indices must either be real positive integers or logicals. I've tried having the hsize loop first but this just saves the results from the final sigma and Mean values at each hsize value. I have also tried creating a logical from the Mean to store the results but this didn't work either. I'm out of ideas, so any help would be greatly appreciated.
0 个评论
采纳的回答
MaryD
2020-4-16
Mean = 0.01:0.01:0.1
hsize = 3:1:26
sigma = 0.5:0.5:5
for m=1:length(Mean)
for h=1:length(hsize)
for s=1:length(sigma)
V=0.01;
noise(m) = imnoise(img,'gaussian',Mean(m),V);
%%%rest of the code
Blur(m,h,s)=...
end
end
end
Try storing your variable like this.
更多回答(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!