Effacer les filtres
Effacer les filtres

Matlab does not show the value of a excel cell

2 vues (au cours des 30 derniers jours)
Eren
Eren le 10 Oct 2023
Commenté : Dyuman Joshi le 27 Oct 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 commentaires
Dyuman Joshi
Dyuman Joshi le 10 Oct 2023
Modifié(e) : Dyuman Joshi le 27 Oct 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 le 10 Oct 2023
Modifié(e) : Stephen23 le 11 Oct 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.

Connectez-vous pour commenter.

Réponses (1)

Pavan Sahith
Pavan Sahith le 27 Oct 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 commentaire
Dyuman Joshi
Dyuman Joshi le 27 Oct 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.

Connectez-vous pour commenter.

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by