How can I input all the results using xlswrite for each loop?

조회 수: 2 (최근 30일)
Braiki Marwa
Braiki Marwa 2017년 8월 8일
편집: Braiki Marwa 2017년 8월 10일
When I run the following code:
for i=1:3
for niter=1:2
img_filtree=smooth_diffusion(I,edgestop(i),'dir',5,niter,0.25);
% figure(1),imshow(img_filtree);
% saveas(figure(1), strcat('Résultats\','img_filtree',num2str(niter),'_edgestop',num2str(i),'.tif'));
imwrite(img_filtree,strcat('Résultats\','img_filtree_',num2str(niter),'-edgestop',num2str(i),'.tif'));%
peaksnr{i,niter}=psnr(img_filtree,Isynth)
snr{i,niter}=psnr(img_filtree,Isynth)
% [peaksnr,snr] = psnr(img_filtree,Isynth)
Ed=edge(img_filtree);
% F= pratt(Ea,Ed);
F{i,niter}= pratt(Ea,Ed)
filename = 'testdata.xlsx';
A = {'PSNR','SNR','FOM'; peaksnr{i,niter}, snr{i,niter},F{i,niter}};
% sheet = 2;
xlRange = 'A1';
% xlswrite(filename,A,sheet,xlRange)
xlswrite(filename,A,xlRange)
end
end
I got just the final result
  댓글 수: 2
Bastien Dietemann
Bastien Dietemann 2017년 8월 8일
I hope to get your question right. You want to save your results in an excel sheet and you are concerned that your results get overwritten each time, correct? If this is the case and you do not care about the layout, you could simply predefine the cells in which you results are saved in. Put
mycells = {'A1','E1','I1';'A4','E4','I4'};
before the loops and then instead of xlRange = 'A1' you write
xlRange=mycells{niter,i};
Does this solve your problem?
Braiki Marwa
Braiki Marwa 2017년 8월 8일
편집: Braiki Marwa 2017년 8월 8일
Thanks Bastien Dietemann for your reply but this solotion can't solve the problem
mycells = {'A1','E1','I1';'A4','E4','I4'};
for i=1:3
for niter=1:2
img_filtree=smooth_diffusion(I,edgestop(i),'dir',5,niter,0.25);
% figure(1),imshow(img_filtree);
% saveas(figure(1), strcat('Résultats\','img_filtree',num2str(niter),'_edgestop',num2str(i),'.tif'));
imwrite(img_filtree,strcat('Résultats\','img_filtree_',num2str(niter),'-edgestop',num2str(i),'.tif'));% [peaksnr1,snr1] = psnr(img_filtree1,Isynth)
peaksnr{i,niter}=psnr(img_filtree,Isynth)
snr{i,niter}=psnr(img_filtree,Isynth)
Ed=edge(img_filtree);
F{i,niter}= pratt(Ea,Ed)
filename = 'testdata.xlsx';
A = {'PSNR','SNR','FOM'; peaksnr, snr,F};
% sheet = 2;
xlRange=mycells{niter,i};
% xlRange = 'A1';
% xlswrite(filename,A,sheet,xlRange)
xlswrite(filename,A,xlRange)
end
end
I want a table like this:

댓글을 달려면 로그인하십시오.

답변 (1개)

Bastien Dietemann
Bastien Dietemann 2017년 8월 9일
편집: Bastien Dietemann 2017년 8월 9일
Okay, let's have another try. I don't have your functions so I cannot test your Version, but this should work.
filename = 'testdata.xlsx';
xlswrite(filename,{'iteration'},1,'A2');
xlswrite(filename,{'edgestop1'},1,'C1');
xlswrite(filename,{'edgestop2'},1,'F1');
xlswrite(filename,{'edgestop3'},1,'I2');
xlswrite(filename,{'PSNR' 'SNR' 'FOM'},'B2:D2');
xlswrite(filename,{'PSNR' 'SNR' 'FOM'},'E2:G2');
xlswrite(filename,{'PSNR' 'SNR' 'FOM'},'H2:J2');
max_niter = 2;
%create destinations
mycells=cell(max_niter,3);
for i =1:max_niter
mycells{i,1}=sprintf('B%i:D%i',i+2,i+2);
mycells{i,2}=sprintf('E%i:G%i',i+2,i+2);
mycells{i,3}=sprintf('H%i:J%i',i+2,i+2);
end
for i=1:3
for niter=1:max_niter
img_filtree=smooth_diffusion(I,edgestop(i),'dir',5,niter,0.25);
% figure(1),imshow(img_filtree);
% saveas(figure(1), strcat('Résultats\','img_filtree',num2str(niter),'_edgestop',num2str(i),'.tif'));
imwrite(img_filtree,strcat('Résultats\','img_filtree_',num2str(niter),'-edgestop',num2str(i),'.tif'));% [peaksnr1,snr1] = psnr(img_filtree1,Isynth)
peaksnr{i,niter}=psnr(img_filtree,Isynth);
snr{i,niter}=psnr(img_filtree,Isynth);
Ed=edge(img_filtree);
F{i,niter}= pratt(Ea,Ed);
A = {peaksnr, snr,F{i,niter}};
xlRange=mycells{niter,i};
xlswrite(filename,A,xlRange)
end
end
  댓글 수: 2
José-Luis
José-Luis 2017년 8월 9일
If performance is an issue (and it will be if you call xlswrite repeatedly), it might be better to use ActiveX controls.
Braiki Marwa
Braiki Marwa 2017년 8월 10일
편집: Braiki Marwa 2017년 8월 10일
Dear Bastien Dietemann, I try your solution, it gives me this result :
I change A = {peaksnr, snr,F{i,niter}}; by A = {peaksnr{i,niter}, snr{i,niter},F{i,niter}}; it gives me this result :
But there are still two problems with this code:
1) edgestop3
2) The number of iteration

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by