Problem writing histogram data to excel - non-English characters and mismatched columns
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Teshan Rezel
il 1 Lug 2021
Risposto: Walter Roberson
il 2 Lug 2021
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 ):
0 Commenti
Risposta accettata
Walter Roberson
il 2 Lug 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()
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Spreadsheets in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!