Matlab does not show the value of a excel cell

5 ビュー (過去 30 日間)
Eren
Eren 2023 年 10 月 10 日
コメント済み: Dyuman Joshi 2023 年 10 月 27 日
Hello I want to compare two Cells of an Excel file. The values of row B are shown normally but the values in row C are shown as some symbols.
Below is the code.
% Path to Excel Sheet and Sheet Page
excelDatei = 'C:\Users\Eren\Documents\MATLAB\Bachelorarbeit\predicted_labels.xlsx';
blattname = 'Classification'; % Ersetzen Sie 'IhrBlattname' durch den Namen Ihres Blatts
% Read Excel-Sheet
data = readtable(excelDatei, 'Sheet', blattname);
% Not necassary now
%srcOrdner = 'C:\Users\Eren\Documents\MATLAB\Verkehrszeichen\Datastore'; % Ersetzen Sie durch den Pfad zu Ihrem Quellordner
%zielOrdner = 'C:\Users\Eren\Documents\MATLAB\Verkehrszeichen\Missclassified'; % Ersetzen Sie durch den Pfad zu Ihrem Zielordner
% Loop to compare both cells
for zeile = 1:size(data, 1)
wertZelleB = char(data{zeile, 'Classification'}); % 'SpalteB' durch den tatsächlichen Spaltennamen in Ihrer Excel-Datei ersetzen
wertZelleC = char(data{zeile, 'TrueLabel'}); % 'SpalteC' durch den tatsächlichen Spaltennamen in Ihrer Excel-Datei ersetzen
if strcmp(wertZelleB, wertZelleC)
fprintf('Die Zellen in Zeile %d sind gleich.\n', zeile);
else
fprintf('Die Zellen in Zeile %d sind unterschiedlich. Wert in Spalte B: %s, Wert in Spalte C: %s\n', zeile, wertZelleB, wertZelleC);
% Hier können Sie den Code zum Verschieben der Dateien hinzufügen, wenn sie unterschiedlich sind.
% Beispiel: copyfile(fullfile(srcOrdner, [imageName '.png']), fullfile(zielOrdner, [imageName '.png']));
end
end
Values for row B are created with this line:
predictedLabels = classify(GTSRBNet, img);
Classification{i} = predictedLabels;
Values for row C are created with these lines:
startRow = 1;
endRow = 12630;
startCol = 7;
endCol = 7;
% Read data out of csv file
data = readmatrix(CopyFile);
% Select rows and collumns
selectedData = data(startRow:endRow, startCol:endCol);
% Convert data into a cellarray
TrueLabel = num2cell(selectedData);
C = table(TrueLabel);
writetable(C, dateipfad, 'Sheet', 'Classification', 'Range', 'C1');
This is the outcome of the code:
  2 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 10 月 10 日
編集済み: Dyuman Joshi 2023 年 10 月 27 日
@Eren - The problem description seems to be incomplete, as it is not clear what exactly your problem is.
Nor is it clear from your code what you are doing.
What is the type of data in the cells that you are trying to compare?
Why convert to a cell array then to a table when you can directly convert to a table by using array2table?
Stephen23
Stephen23 2023 年 10 月 10 日
編集済み: Stephen23 2023 年 10 月 11 日
"The values of row B are shown normally but the values in row C are shown as some symbols. "
Note: "Spalte" translates as column, not row.

サインインしてコメントする。

回答 (1 件)

Pavan Sahith
Pavan Sahith 2023 年 10 月 27 日
Hello Eren,
I understand you want to read the C row's data from '.csv' file and compare the strings in B and C rows.
I can see that you are using "readmatrix" to fetch the data into C row, but According to the MathWorks documentation, "readmatrix" is essentially limited to numeric data by default.
As a workaround using "readcell" or "readmatrix" in the following way will help
data=readmatrix(filename, 'OutputType','string');
Please refer to the following MathWorks documentation to know more about
Hope this helps.
Thanks & Regards
Pavan Sahith
  1 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 10 月 27 日
"... compare the strings in B and C rows."
Where has OP specified that the data is in string format?
You are assuming that the problem is with readmatrix(). csv files can contain numeric data as well.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by