import data from csv and plot it
5 views (last 30 days)
Show older comments
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 Comment
dpb
on 6 Feb 2023
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.
Accepted Answer
Star Strider
on 6 Feb 2023
Edited: Star Strider
on 6 Feb 2023
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 Comments
More Answers (1)
Vilém Frynta
on 6 Feb 2023
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 Comment
dpb
on 6 Feb 2023
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.
See Also
Categories
Find more on Data Import from MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!