cannot load csv file
조회 수: 8 (최근 30일)
이전 댓글 표시
Hi , I am new to matlab and I face this error each time I try to load my csv file using the dbload command in iris TOOLBOX.
d=dbload('data.csv')
d =
struct with no fields.
how can I solve this problem?
댓글 수: 0
답변 (1개)
Image Analyst
2025년 5월 9일
편집: Image Analyst
2025년 5월 9일
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
댓글 수: 5
Image Analyst
2025년 5월 9일
Try this:
d = importdata('data.csv')
numericalData = d.data;
% Get 7 column names. Adjust column indexes as needed.
columnNames = d.textdata(1, 2:end-1)
% Convert to a table if you want to associate the variables with the columns.
t = array2table(numericalData, VariableNames = columnNames)
Walter Roberson
2025년 5월 9일
My speculation is that dbload() is having problems because the first field is not quoted with "" but still contains characters ('Q')
If so then possibly the 'preprocess' option of dbload() would be useful. 'proprocess' takes a function handle, with the function accepting a character vector and returning a character vector. You could put in a function handle to a function that puts " quotes around the first portion of text, such as
d = dbload('data.csv', 'preprocess', @PrePro)
function S = PrePro(S)
S = regexprep(S, '^(\w+)', '"$1"', 'lineanchors');
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!