import data from csv and plot it
조회 수: 12 (최근 30일)
이전 댓글 표시
Hey,
I need to import data from this csv-file and plot it. I tried to use this code but i get the Nan in every single value in the matrix.
a1_Au1EchemPEG = readmatrix('23-02-03(S1).csv', 'Range', 'A2:X14954');
xaxis=a1_Au1EchemPEG(:,1);
yaxis = a1_Au1EchemPEG(:,6);
plot(xaxis, yaxis)
댓글 수: 1
dpb
2023년 2월 6일
It isn't a text file; can override and open it in Excel but only in protected view and not going to take the time to fight it here.
Open the file in Excel and save as an Excel file -- you can't change an Excel file/name from on storage format to another by just copy or rename; it has to rewrite the file in the new/different format.
채택된 답변
Star Strider
2023년 2월 6일
편집: Star Strider
2023년 2월 6일
I opened it in Excel, did a straightforward manual copy-paste to Notebook, and saved it to a text file (that I uploaded here).
Use the text file instead —
a1_Au1EchemPEG = readtable('23-02-03(S1).txt', 'VariableNamingRule','preserve')
VN = a1_Au1EchemPEG.Properties.VariableNames;
xaxis=a1_Au1EchemPEG{:,1};
yaxis = a1_Au1EchemPEG{:,6};
figure
plot(xaxis, yaxis)
grid
xlabel(strrep(VN{1}, '_','\_'))
ylabel(strrep(VN{6}, '_','\_'))
title(strrep('a1_Au1EchemPEG', '_','\_'))
yaxis = fillmissing(yaxis, 'nearest'); % Recommended
yaxis = detrend(yaxis, 1); % Optional
figure
plot(xaxis, yaxis)
grid
xlabel(strrep(VN{1}, '_','\_'))
ylabel(strrep(VN{6}, '_','\_'))
title(strrep('a1_Au1EchemPEG', '_','\_'))
EDIT — Corrected typographical error.
.
댓글 수: 0
추가 답변 (1개)
Vilém Frynta
2023년 2월 6일
I looked at your data and it looks like your decimal numbers are separated by a decimal "comma" (,), which can cause problems because Matlab separates numbers with a decimal point (.). You can try to edit your file by replacing all commas into points, which can be usually done simply with some kind of "find and replace" function (in Excel, for example).
I viewed your data via Excel, so I'm not 100 % sure whether it's just how Excel interpreted your data. I failed to check your data via Notepad or any other simple text app. That may also be a problem with loading your data. Maybe they are somehow encrypted?
댓글 수: 1
dpb
2023년 2월 6일
An ordinary text editor here (MATLAB editor) had issue with fonts, apparently; what made me think was an Excel file. If your OS has a set of installed fonts that map the OP's character set to something legible, then readmatrix and friends have the optional parameter-value pair, 'DecimalSeparator'
OP should then try
a1_Au1EchemPEG=readmatrix('23-02-03(S1).csv','Range','A2:X14954','DecimalSeparator',',');
Of course, then there's an issue of what is the field delimiter to solve so it doesn't conflict.
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!