Readtable and Readmatrix Ignore Specified Range and Produce Extra Variables
6 ビュー (過去 30 日間)
古いコメントを表示
I have this very simple code:
type 2025-03-28_02-07_10-0.csv
in1 = readtable('2025-03-28_02-07_10-0.csv', 'ReadVariableNames', false, 'Range', 'C2:C3')
in2 = readtable('2025-03-28_02-07_10-0.csv', 'ReadVariableNames', false, 'Range', 'C2:D3')
stupid_matlab = readtable('PATH', 'ReadVariableNames', false, 'Range', strcat('C2:D', string(ri_length)));
However, it completely ignores the column portion of the range I give it. Changing the number part of the specified range changes the number of rows, but it always produces four extra columns. If I specify C2:C3, I get five columns. If I specify C2:D3, I get six columns. I have not idea where it is getting the extra columns from. I have also tried "readmatrix" and it does the exact same thing. I've attatched the .csv, but I've opened it directly and in excel and don't see anything wrong.
0 件のコメント
採用された回答
Dyuman Joshi
2025 年 6 月 20 日
From what I have understood of your query, you need to specify that you don't require Extra columns -
in = readtable('2025-03-28_02-07_10-0.csv', 'ReadVariableNames', false)
%Specifying a range
in = readtable('2025-03-28_02-07_10-0.csv', 'ReadVariableNames', false, 'Range', 'B1:H5')
%Specifying a range with no extra variable creation
in = readtable('2025-03-28_02-07_10-0.csv', 'ReadVariableNames', false, 'Range', 'B1:H5', ...
'ExtraColumnsRule', 'ignore')
その他の回答 (2 件)
dpb
2025 年 6 月 20 日
d=dir('*.csv');
opt=detectImportOptions(d.name);
tin=readtable(d.name,'Range','C2:C3','ExtraColumnsRule','ignore')
I don't know if Mathworks would classify the behavior as a bug or not, but is unexpected, granted. Probably worth submitting a report as a quality of implementation issue. It's complicated, so not terribly surprising there are still some warts hanging about.
You can give it a little extra help as above to avoid the issue...
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Graphics Object Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!