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