Effacer les filtres
Effacer les filtres

How can i save data from 1*5 cell array into excel file. I have 5 images in loop and i extract glcm features now i want to save each imgaes features but only the last image data is saved.

2 vues (au cours des 30 derniers jours)
%path D:\matlab\data\Training\glossy\*.jpg
path='D:\matlab\data\Training\test\';
list=dir([path, '*.jpg']);
for x=1:length(list)
images{x}=imread([path, list(x).name]);
if length(size(images{x}))==3 %check if the image I is color
I=rgb2gray(images{x});
end;
offsets0 = [0 1; -1 1; -1 0; -1 -1];
glcm1 = graycomatrix(I,'offset',offsets0);
stats{x} = graycoprops(glcm1,{'all'});
writetable(struct2table(stats{x}), 'test_glcmfeatures.csv')
end
  1 commentaire
dpb
dpb le 24 Août 2018
writetable doesn't append (as you found out) unless you use it to write Excel files and use the 'Range' argument to set a location.
Probably simplest solution is to move the write until after the loop finishes and then write the whole array at once.

Connectez-vous pour commenter.

Réponse acceptée

Adam Danz
Adam Danz le 24 Août 2018
Modifié(e) : Adam Danz le 24 Août 2018
A snippet from your code:
for x=1:length(list)
...
writetable(struct2table(stats{x}), 'test_glcmfeatures.csv')
end
You are overwriting test_glcmfeatures.csv on every iteration of the loop.
Instead, one solution would be to change the file name and create a new file on each iteration.
for x=1:length(list)
...
writetable(struct2table(stats{x}), sprintf('test_glcmfeatures_%d.csv', x))
end
Alternatively, if you want to write everything to the same file, try using the ' range ' (link) property. [Addendum] Or, as @dpb pointed out, you could just collect all of the stats data within the look at write it all in one file after the loop (which would be simpler than using the 'range' property).
  9 commentaires
Anjali Acharya
Anjali Acharya le 25 Août 2018
For now I have features value saved in csv file for last 5th image only in this format as shown in figure below:
Anjali Acharya
Anjali Acharya le 25 Août 2018
Hello #dbp i want to use these features for training a classifier ad use it for texture classification. I will resize all image to some fix size may be 512*512 before GLCM features.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by