import data from csv and plot it
11 ビュー (過去 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!