'readtable' in 2023 version error (This issue did not occur in 2018)

6 ビュー (過去 30 日間)
Si
Si 2024 年 3 月 23 日
編集済み: Walter Roberson 2024 年 3 月 23 日
Ele_intensity = readtable('electricity_consumption_carbon_intensity.csv');
Ele_intensity= Ele_intensity{1105:1152,2}; %Import data from row 1105 to 1152 ,column 2
Gas_intensity = readtable('gas_consumption_carbon_intensity.csv');
Gas_intensity= Gas_intensity{481:528,2}; %Import data from row 481 to 528 ,column 2
Ele_Quantity = readtable('electricity_consumption_quantity_price.csv');
Ele_Quantity= Ele_Quantity{1105:1152,2}; %Import data from row 1105 to 1152 ,column 2
Gas_Quantity = readtable('gas_consumption_quantity_price.csv');
Gas_Quantity= Gas_Quantity{481:528,2}; %Import data from row 481 to 528 ,column 2
The last four rows of code successfully import data from the csv document in both 2023b and 2018b,but the first four rows of code only import the right data in R2018b and in 2023b the array only has many 3. So I was wondering what was wrong with that,and is that code incompatible in two versions?
  2 件のコメント
Dyuman Joshi
Dyuman Joshi 2024 年 3 月 23 日
How readtable() handles titles, headers etc might have changed from R2018b to R2023b.
You should check and compare the respective documentations to see what changes have been made.
Additionally, you can ese detectImportOptions for both versions and see the output.
Si
Si 2024 年 3 月 23 日
編集済み: Walter Roberson 2024 年 3 月 23 日
opts =
DelimitedTextImportOptions -
Delimiter: {'/'}
Whitespace: '\b\t '
LineEnding: {'\n' '\r' '\r\n'}
CommentStyle: {}
ConsecutiveDelimitersRule: 'split'
LeadingDelimitersRule: 'keep'
TrailingDelimitersRule: 'ignore'
EmptyLineRule: 'skip'
Encoding: 'UTF-8'
MissingRule: 'fill'
ImportErrorRule: 'fill'
ExtraColumnsRule: 'addvars'
VariableNames: {'Var1', 'Var2', 'Var3'}
VariableTypes: {'double', 'double', 'char'}
SelectedVariableNames: {'Var1', 'Var2', 'Var3'}
VariableOptions: 显示所有 3 VariableOptions
使用 setvaropts/getvaropts 访问 VariableOptions 子属性
VariableNamingRule: 'modify'
DataLines: [2 Inf]
VariableNamesLine: 0
RowNamesColumn: 0
VariableUnitsLine: 0
VariableDescriptionsLine: 0
This is the CSV document,and that shows the time in first column,and the data I need is in the second column
This is what matlab shows when import the whole document ,the ’carbon intensity‘column appear in the same column as time,and there are two additional columns that does not show up on the original csv file.
Thank you for your reply

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

採用された回答

Star Strider
Star Strider 2024 年 3 月 23 日
I do not understand ‘2023b the array only has many 3’, however I believe that the shortened table display in the last few releases is simply a display issue. The entire file is being imported correctly.
  6 件のコメント
Si
Si 2024 年 3 月 23 日
Thank you!!!! It’s working!!Thank you for your help!
Star Strider
Star Strider 2024 年 3 月 23 日
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by