import data from csv and plot it

11 ビュー (過去 30 日間)
Mohamed Asaad
Mohamed Asaad 2023 年 2 月 6 日
編集済み: Star Strider 2023 年 2 月 6 日
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
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
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')
a1_Au1EchemPEG = 16522×13 table
Time_1 F_1:1 D_1:1 F_1:3 D_1:3 F_1:5 D_1:5 F_1:7 D_1:7 F_1:9 D_1:9 Meas. Temp. Time Tact ______ ___________ ________ ___________ __________ __________ _________ ___________ _________ ___________ ________ ________________ ______ 2.1274 0 0 -5.8435e-10 0 6.4665e-10 0 -6.7303e-10 0 -5.8435e-10 0 0.099139 22.779 7.9166 -0.00013316 0.048783 -0.11003 0.0065207 0.021789 0.0010854 0.1165 -0.017166 0.1493 0.012442 1.101 22.79 11.778 -0.16484 0.1025 0.073485 0.059092 0.012532 0.052307 0.16709 0.029072 0.095061 0.021866 2.0971 22.79 15.641 -0.077195 0.16441 0.14382 -0.0055798 0.035517 0.12101 0.099842 0.056434 0.19457 0.07572 3.0991 22.79 19.499 -0.095694 0.28676 0.059254 0.14156 0.060122 0.093144 0.22117 0.060224 0.078032 0.027037 4.101 22.79 23.36 -0.015155 0.3473 0.31017 0.16297 0.17436 0.14529 0.21292 0.067222 0.20833 0.030092 5.101 22.79 27.217 -0.23376 0.2828 0.062487 0.18546 0.15281 0.16519 0.32812 0.067146 0.3332 0.043705 6.097 22.79 31.078 0.016588 0.41232 0.38428 0.1796 0.20241 0.14924 0.47784 0.16568 0.28838 0.03975 7.099 22.79 34.939 0.10331 0.45731 0.29721 0.19297 0.39775 0.12892 0.45003 0.11387 0.36872 0.07187 8.0971 22.79 38.798 -0.024663 0.49277 0.18084 0.16466 0.2459 0.22174 0.46049 0.12016 0.50215 0.052013 9.101 22.781 42.658 0.1027 0.62135 0.26922 0.26064 0.43467 0.27987 0.50749 0.12037 0.48488 0.072177 10.101 22.79 46.517 0.16508 0.53447 0.32105 0.24193 0.42918 0.23959 0.55167 0.14591 0.58645 0.093115 11.109 22.767 50.377 0.067744 0.61998 0.47404 0.23878 0.60711 0.17039 0.62674 0.16747 0.49676 0.093113 12.101 22.767 54.238 0.22204 0.66433 0.39948 0.31251 0.59274 0.26935 0.63626 0.11614 0.62626 0.10959 13.101 22.767 58.098 0.30894 0.72598 0.72957 0.29781 0.47754 0.3009 0.75785 0.18117 0.75967 0.07206 14.099 22.756 61.961 0.19755 0.83513 0.58378 0.27361 0.69274 0.30012 0.82328 0.18566 0.737 0.073577 15.109 22.752
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.
.

その他の回答 (1 件)

Vilém Frynta
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
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 ExchangeData Import from MATLAB についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by