import data from csv and plot it
5 次查看(过去 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!