Problem writing histogram data to excel - non-English characters and mismatched columns

1 view (last 30 days)
Hi folks,
I am trying to write image histogram data to excel, for various images. However, I am running into a problem where the output doesn't match what I would expect.
I want to have 5 columns (pixel value, R, G, B and Grey), with 256 rows for each.
My code is as follows:
headings = {'Pixel Value', 'R', 'G', 'B', 'Grey'};
pixelValue = 0:255;
pixelValue = pixelValue';
allCokeMask(:,:,1) = uint8(allCokeSeries_plane1);
allCokeMask(:,:,2) = uint8(allCokeSeries_plane2);
allCokeMask(:,:,3) = uint8(allCokeSeries_plane3);
allCoke_R = imhist(allCokeMask(:,:,1));
allCoke_G = imhist(allCokeMask(:,:,2));
allCoke_B = imhist(allCokeMask(:,:,3));
allCokeGrey = imhist(rgb2gray(allCokeMask));
dataCollectionAllCoke = [headings; num2cell(pixelValue), num2cell(allCoke_R), num2cell(allCoke_G), num2cell(allCoke_B), num2cell(allCokeGrey)];
dataCollectionAllCoke = cell2table(dataCollectionAllCoke);
writetable(dataCollectionAllCoke, resultsPath, 'Sheet', nameStringExcel, "Range", 'A1');
The output I'm getting looks like this (dataCollectionAllCoke is a ):

Accepted Answer

Walter Roberson
Walter Roberson on 2 Jul 2021
dataCollectionAllCoke = cell2table(dataCollectionAllCoke);
You have a cell array in which the first rows are text.
When you cell2table() the type of each column is determined by the type of the data in the first row of the column. Since that is text, MATLAB is effectively taking char() of the numeric values, resulting in Unicode characters being displayed.
You should use writecell() instead of converting to table and using writetable()

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!