Is it possible to increment the excel sheet value each time so tat at the end of run

조회 수: 3 (최근 30일)
This is my simple pgm to calcualte glcm features for 10 images... for all the 10 images the feature value should be written in excel sheet, i have done with xlswrite option. the problem i have is only the feature value of last image is written in excel sheet..
is it possible to increment the excel sheet value each time so tat at the end of run.. all features for 10 images is stored in excel sheet????
like.. Image1 - fea1 fea2 ..... fea16 Image2 - fea1 fea2 ..... fea16
numImgs = 10;
for imgNum = 1 : numImgs
fprintf('Computing Texture..... %d...\n', imgNum);
img = imread(sprintf('samplepics/%d.jpg',imgNum)); %its a gray scale image
offsets0 = [0 1;-1 1;-1 0;-1 -1];
glcms = graycomatrix(i,'Offset',offsets0);
stats = graycoprops(glcms, {'contrast','homogeneity','Energy','Correlation'});
g1=stats.Contrast;
g2=stats.Homogeneity;
g3=stats.Energy;
g4=stats.Correlation;
gg=struct2cell(stats); % toally 16 features
xlswrite('feature.xls',[g1 g2 g3 g4],'Sheet3','b2:q2')
end
Thanks in advance

채택된 답변

Walter Roberson
Walter Roberson 2013년 12월 25일
You would need to keep track of it yourself and change the offset. As you are specifying the sheet name you can do it with just the starting letter and column.
Easier would be to store everything and write it once.
gdata = cell(numImgs,1);
for imgNum = 1 : numImgs
fprintf('Computing Texture..... %d...\n', imgNum);
img = imread(sprintf('samplepics/%d.jpg',imgNum)); %its a gray scale image
offsets0 = [0 1;-1 1;-1 0;-1 -1];
glcms = graycomatrix(i,'Offset',offsets0);
stats = graycoprops(glcms, {'contrast','homogeneity','Energy','Correlation'});
g1=stats.Contrast;
g2=stats.Homogeneity;
g3=stats.Energy;
g4=stats.Correlation;
gg=struct2cell(stats); % toally 16 features -> not used?
gdata{imgNum} = [g1 g2 g3 g4];
end
xlswrite('feature.xls', gdata, 'Sheet3','b2')
  댓글 수: 1
Subha
Subha 2013년 12월 25일
Thanks a lot sir... it really worked... while running the program the data was not written in sheet3.. then i tried few combination and added cell2mat after end .. after this it has been written.. thanks for timely help sir.. ...
gdata{imgNum} = [g1 g2 g3 g4]; end m=cell2mat(gdata) xlswrite('feature.xls', m, 'Sheet3','b2')
.....

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

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by