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

1 次查看(过去 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 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by