24 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Lalit Kumar am 29 Apr. 2022
Bearbeitet: Prasanna Konyala am 2 Mai 2022
- TestCase.xlsx
Hi,
I have created a script which is reading data from excel in matlab 2017v.It's reading whole excel file as it is ,without adding "" for missing value ,not omitiitng any row and setting variable name = VAR1,VAR2....etc
file_name = 'TestCase.xlsx';
excel_sheet = readtable(file_name,'Sheet',1,'ReadVariableNames',false);
Now i have tried running same script in the matlab2020v,it's reading excel in a different way than 2017v.It's omitting row and reading first line as VarName.
file_name = 'TestCase.xlsx';
excel_sheet = readtable(file_name,'Sheet',1,'ReadVariableNames',false);
Update:Added Image
I want MATLAB2020A read excel in the format as it's read by 2017A
5 Kommentare 3 ältere Kommentare anzeigen3 ältere Kommentare ausblenden
3 ältere Kommentare anzeigen3 ältere Kommentare ausblenden
Star Strider am 29 Apr. 2022
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/1708145-readtable-producing-different-result-for-2017-and-2020a-matlab-version#comment_2132030
⋮
The file appears to be made up of several blocks of data.
file_name = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/982945/TestCase.xlsx';
cell_sheet = readcell(file_name)
cell_sheet = 35×8 cell array
{'<TV>TestCase1:1'} {1×1 missing } {1×1 missing } {1×1 missing } {1×1 missing } {1×1 missing } {1×1 missing } {1×1 missing } {'Time' } {'Inlet_Volatge_Sensor_Diag'} {'Inlet_Volatge_Sensor_volt'} {'Charging_Started_Latch'} {'Normal_Charging_Shutdown1'} {'VCharg_Act1' } {'CCS_EV_Inlet_voltage'} {'Sensor Validity'} {'single' } {'boolean' } {'uint8' } {'boolean' } {'boolean' } {'fixdt(1,32,16)'} {'fixdt(1,32,16)' } {'uint8' } {[ 0]} {[ 0]} {[ 1]} {[ 0]} {[ 0]} {[ 0]} {[ 0]} {[ 1]} {[ 1]} {[ 0]} {[ 1]} {[ 0]} {[ 0]} {[ 0]} {[ 0]} {[ 1]} {[ 2]} {[ 0]} {[ 1]} {[ 0]} {[ 0]} {[ 0]} {[ 0]} {[ 1]} {[ 3]} {[ 0]} {[ 1]} {[ 0]} {[ 0]} {[ 0]} {[ 0]} {[ 1]} {[ 4]} {[ 0]} {[ 1]} {[ 0]} {[ 0]} {[ 0]} {[ 0]} {[ 1]} {1×1 missing } {1×1 missing } {1×1 missing } {1×1 missing } {1×1 missing } {1×1 missing } {1×1 missing } {1×1 missing } {'<TV>TestCase1:2'} {1×1 missing } {1×1 missing } {1×1 missing } {1×1 missing } {1×1 missing } {1×1 missing } {1×1 missing } {'Time' } {'Inlet_Volatge_Sensor_Diag'} {'Inlet_Volatge_Sensor_volt'} {'Charging_Started_Latch'} {'Normal_Charging_Shutdown1'} {'VCharg_Act1' } {'CCS_EV_Inlet_voltage'} {'Sensor Validity'} {'single' } {'boolean' } {'uint8' } {'boolean' } {'boolean' } {'fixdt(1,32,16)'} {'fixdt(1,32,16)' } {'uint8' } {[ 0]} {[ 0]} {[ 1]} {[ 0]} {[ 0]} {[ 0]} {[ 1]} {[ 1]} {[ 1]} {[ 0]} {[ 1]} {[ 0]} {[ 0]} {[ 0]} {[ 1]} {[ 1]} {[ 2]} {[ 0]} {[ 1]} {[ 0]} {[ 0]} {[ 0]} {[ 1]} {[ 1]} {[ 3]} {[ 0]} {[ 1]} {[ 0]} {[ 0]} {[ 0]} {[ 1]} {[ 1]}
What do you want to do with it?
Lalit Kumar am 29 Apr. 2022
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/1708145-readtable-producing-different-result-for-2017-and-2020a-matlab-version#comment_2132055
Bearbeitet: Lalit Kumar am 29 Apr. 2022
I wanted to read whole file in the MATLAB2020 using "readTable" without omitting any information ,after that i know how to process data to convert them into TestCase.
My intend is to run same .m script in both 2017 and 2020 version.
readcell is not available in mat2017B
Jan am 29 Apr. 2022
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/1708145-readtable-producing-different-result-for-2017-and-2020a-matlab-version#comment_2132105
Bearbeitet: Jan am 29 Apr. 2022
Of course you can implement branching:
if verLessThan('matlab', '9.8')
excel_sheet = readtable(file_name,'Sheet',1,'ReadVariableNames',false);
else
excel_sheet = readcell(file_name);
end
The general problem remains: Matlab versions are not perfectly compatible. The need to run a code in different Matlab versions requires to find workarounds.
In the lab I'm working in, we still run a virtual machine unter WindowsXP, because the reference implementation of a code for clinical decision making was developped in Matlab 6.5 (2002). A validation of the results under Matlab R2009a took 2 month, because the outcome of 1000 patients have to be compared. It took me 1 year to implement an automatic comparison of the results, such that the migration to Matlab 2018b needed 48 hours only. During the tests a bunch of incompatibilities have been found, e.g. in strncmp, if the inputs are empty and n=0, or fopen() in VAXD format.
Do not try to write a "one-code fits all Matlab versions" program, because this letexplode the complexity of maintaining the code. Rely on unit-test: Import a reference file in R2017a, save the result as a MAT file. Insert a branching as shown above and let it import the Excel file again. Now compare the results with the contents of the MAT file. If this is equivalen, it is a strong hint, that your import is working. Afterwards run these tests whenever you change the Matlab version.
My software for clinical decision making includes 100'000 lines of dull test codes only to validate the output of the subfunctions.
dpb am 29 Apr. 2022
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/1708145-readtable-producing-different-result-for-2017-and-2020a-matlab-version#comment_2132715
Bearbeitet: dpb am 29 Apr. 2022
I'd probably go back a step and use an import object that matches the expected file structure and form in which want the file to be interpreted. This then should produce the desired consistent results.
I don't know what your 2017 imported file looked like; be good to attach it as a .mat file, but R2020b didn't seem to leave anything out and didn't read variable names...
Lalit Kumar am 30 Apr. 2022
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/1708145-readtable-producing-different-result-for-2017-and-2020a-matlab-version#comment_2133290
@dpb added image for better understanding
Melden Sie sich an, um zu kommentieren.
Melden Sie sich an, um diese Frage zu beantworten.
Antworten (1)
Prasanna Konyala am 2 Mai 2022
Bearbeitet: Prasanna Konyala am 2 Mai 2022
Hi @Lalit Kumar
From my understanding, you want to get the whole data in excel to be read in the same format as 2017a.
From 2020a, "readtable()" functionality is a bit different than earlier versions. It can detect data types, discard extra header lines, and fill in missing values. In the file attached, it is discarding extra header lines at the start and reading each column as numeric data. Hence, unknown or missing data is replaced by NaN.
If you want the functionality as earlier versions, you can add ('Format','auto') name-value pair argument to the readtable function in 2020a.
file_name = 'TestCase.xlsx';
excel_sheet = readtable(file_name,'Sheet',1,'ReadVariableNames',false,'Format','auto');
Please refer this document for more information about "readtable()"
0 Kommentare -2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden
-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden
Melden Sie sich an, um zu kommentieren.
Melden Sie sich an, um diese Frage zu beantworten.
Siehe auch
Kategorien
MATLABData Import and AnalysisData Import and ExportStandard File FormatsSpreadsheets
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Es ist ein Fehler aufgetreten
Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
Amerika
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asien-Pazifik
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Kontakt zu Ihrer lokalen Niederlassung