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

조회 수: 1 (최근 30일)
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 ):

채택된 답변

Walter Roberson
Walter Roberson 2021년 7월 2일
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()

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by