Matlab does not show the value of a excel cell
조회 수: 4 (최근 30일)
이전 댓글 표시
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
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?
답변 (1개)
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
"readmatrix"- https://in.mathworks.com/help/matlab/ref/readmatrix.html
Hope this helps.
Thanks & Regards
Pavan Sahith
댓글 수: 1
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 Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!