Matlab does not show the value of a excel cell

4 Ansichten (letzte 30 Tage)
Eren
Eren am 10 Okt. 2023
Kommentiert: Dyuman Joshi am 27 Okt. 2023
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 Kommentare
Dyuman Joshi
Dyuman Joshi am 10 Okt. 2023
Bearbeitet: Dyuman Joshi am 27 Okt. 2023
@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 am 10 Okt. 2023
Bearbeitet: Stephen23 am 11 Okt. 2023
"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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Pavan Sahith
Pavan Sahith am 27 Okt. 2023
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 Kommentar
Dyuman Joshi
Dyuman Joshi am 27 Okt. 2023
"... 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.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by