0

In my GUI I am using this matlab code to store the values in excel sheet.This code is calculating the glcm six features.

function [Contrast,cor,ener,homo,Var,Entropy] = glcm_feature_extraction(I1)

Contrast = graycoprops(graycomatrix(rgb2gray(I1)),'Contrast')  
cor= graycoprops(graycomatrix(rgb2gray(I1)), 'Correlation')  
ener = graycoprops(graycomatrix(rgb2gray(I1)), 'Energy')  
homo = graycoprops(graycomatrix(rgb2gray(I1)), 'Homogeneity')  
img = double(I1);  
Var = var((img(:)))  
Entropy=entropy(I1)

Here suppose I get these values after calculation:

[0.603606103 : 0.785092239 : 0.271728411 : 0.855429408 :1889.578963 : 7.178149206]

But iI need only approx value like:

[0.6 : 0.7 : .2 ....]

How to modify this code to get this result?

Tonechas
  • 13,398
  • 16
  • 46
  • 80
  • 1
    You can round values up to `N` digits to the right of the decimal point by using `x_round = round(x, N)`. See the documentation for [`round`](https://www.mathworks.com/help/matlab/ref/round.html) for more information. – buzjwa Mar 30 '15 at 13:10
  • I am getting error Error using ==> round Too many input arguments. – preeti yadav Mar 31 '15 at 10:37

1 Answers1

0

For example, lets consider Contrast=0.603606103

And you wanted to make approximately as 0.6 then use the following :

sprintf('%.1f',Contrast);

which should give you result exactly Contrast=0.6

Similarly do it for all remaining 5 variables.

  • I have used this y=sprintf('%.1f',Contrast); stored it in excel xlswrite('abc.xlsx',[y]); I am not getting the correct results as in excel file the result 0.6 is taking three cells to store itself rather than one in excel file thanks in advance – preeti yadav Mar 31 '15 at 15:28