matlab code to store GLCM features into an Excel sheet..
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
Share a link to this question
here i have a code after reading an image ... it is resized and GLCM is calculated .. this GLCM features are calculated for folder of images... and I need this to be stored in an excel ... the code i used is:
RGB=imresize(image,[256 256]);
I=rgb2gray(RGB);
I2=graycomatrix(I);
I3=graycoprops(I2);
usecel{1}=I3;
file1 = 'C:\Program Files\hemaMATLAB\R2007b\work\glcmfeatures.xlsx';
xlswrite(file1,usecel{1});
but the below code is giving an error like: ??? Error using ==> xlswrite at 114 Input data must be a numeric, cell, or logical array.
please tell me how to write a matlab code to store GLCM features to store in an Excel sheet.... I need this for comparison.
Accepted Answer
KSSV
on 3 Jul 2017
Use this:
writetable(struct2table(I3), 'glcmfeatures.xlsx')
9 Comments
hp
on 3 Jul 2017
It is giving error as below:
??? Undefined function or method 'struct2table' for input arguments of type 'struct'.
what to do...
the value of I3 is: I3 =
Contrast: 0.3396
Correlation: 0.9659
Energy: 0.2668
Homogeneity: 0.9449
KSSV
on 3 Jul 2017
Edited: Image Analyst
on 3 Jul 2017
writetable and struct2table were introduced in 2013b. What version you are in?
KSSV
on 3 Jul 2017
Try this:
P = [fieldnames(I3),struct2cell(I3)] ;
xlswrite('myfile.xlsx',P) ;
Image Analyst
on 3 Jul 2017
According to what's in "file1", it's the R2007b version. But your code should work with that antique version once the folder is changed. Windows will prevent the file from being written to any folder under Program Files, such as 'C:\Program Files\hemaMATLAB\R2007b\work';
hp
on 4 Jul 2017
I am using R2007b (antique)version only(bcoz i tried to buy new version they sent msg that they will call within 24 hours but no call i got and I downloaded the trial version but it is not installing.. its giving error..so unable to get new version i tried a lot..... so I had no option using antique one :( hmm..)
And its working... I am very much grateful to you.. THANK YOU SO MUCH.. and I need to copy some 20 image details into an Excel sheet ... how to do it..
hp
on 4 Jul 2017
And here GLCM is having 4rows of details ... I did writing one line of data into XLSSHEET using for loop... but here for every image i need to store 4lines of details into an excel sheet and after 4lines at 5th line another 4lines of details should be stored like this it should go on copying 4lines details for every image(there are 20 images)please help ...
KSSV
on 4 Jul 2017
YOu may proceed like this:
P = [fieldnames(I3) struct2cell(I3)] ;
% append more values in loop
Pcell = cell(6,4) ;
Pcell(1:2,:) = P' ;
for i = 3:6
Pcell(i,:) = num2cell(rand(1,4)) ;
end
xlswrite('myfile.xlsx',Pcell) ;
hp
on 5 Jul 2017
I tried the code below: dir_in = 'C:\Program Files\hemaMATLAB\R2007b\work\capinput\';
dir_out = 'C:\Program Files\hemaMATLAB\R2007b\work\output\';
file_ext = 'jpg';
listing = dir(strcat(dir_in,'i*.',file_ext));
file_names = {listing.name};
num_pages = length(file_names);
gdata = cell(num_pages,1);
for imgNum = 1 : num_pages
fprintf('Computing Texture..... %d...\n', imgNum);
image = rgb2gray(imread(strcat(dir_in,file_names{imgNum})));
RGB=imresize(I,[256 256]);
I=rgb2gray(RGB);
I2=graycomatrix(I);
I3=graycoprops(I2);
P = [fieldnames(I3),struct2cell(I3)] ;
P = [fieldnames(I3) struct2cell(I3)] ;
% append more values in loop
Pcell = cell(6,4) ;
Pcell(1:2,:) = P' ;
for i = 3:6
Pcell(i,:) = num2cell(rand(1,4)) ;
end
xlswrite('myfile.xlsx',Pcell) ;
end
and the above code is giving error as follows:
Processing an Image: 1
??? Error using ==> rgb2gray>parse_inputs at 82
MAP must be a m x 3 array.
Error in ==> rgb2gray at 35
X = parse_inputs(varargin{:});
Error in ==> texturetest1 at 21
I=rgb2gray(map);
??? 4lines_of_feature_into_xlsheet |
Error: Unexpected MATLAB expression.
hp
on 5 Jul 2017
sorry the above code is not corrected ... here is the code below ... which is giving error:
dir_in = 'C:\Program Files\hemaMATLAB\R2007b\work\capinput\';
dir_out = 'C:\Program Files\hemaMATLAB\R2007b\work\output\';
file_ext = 'jpg';
listing = dir(strcat(dir_in,'i*.',file_ext));
file_names = {listing.name};
num_pages = length(file_names);
for imgNum = 1 : num_pages
fprintf('Computing Texture..... %d...\n', imgNum);
image = rgb2gray(imread(strcat(dir_in,file_names{imgNum})));
I=imresize(image,[256 256]);
I2=graycomatrix(I);
I3=graycoprops(I2);
P = [fieldnames(I3),struct2cell(I3)] ;
P = [fieldnames(I3) struct2cell(I3)] ;
% append more values in loop
Pcell = cell(6,4) ;
Pcell(1:2,:) = P' ;
for i = 3:6
Pcell(i,:) = num2cell(rand(1,4)) ;
end
xlswrite('myfile.xlsx',Pcell) ;
end
and the error is:
Computing Texture..... 1...
??? Index exceeds matrix dimensions.
Error in ==> fourfeatureExcelsheet at 21
Pcell = cell(6,4) ;
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Products
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)