How can I import from Excel CSV

11 ビュー (過去 30 日間)
EW
EW 2020 年 11 月 24 日
コメント済み: Star Strider 2020 年 11 月 24 日
I have a device that measures time and three other variables (X, Y, Z). The data always starts at row 24 but the end row is different for every file (in the case of the sample file it is row 33303). The device saves the data in a .csv file (attached)
I want to be able to create an app that will allow me to do the following
1) Browse and select the file
2) Import each variable (time, x, y, z) as a vector over the range (starting at row 24)
3) Analyze the data
I figured out step 1 and I have code for step 3 but I'm having trouble with the import over the specific file range. Either I can't get it to work or I'm able to only import part of the data.
Thanks!

採用された回答

Star Strider
Star Strider 2020 年 11 月 24 日
編集済み: Star Strider 2020 年 11 月 24 日
Use readtable to read it:
T1 = readtable('sample.csv', 'VariableNamingRule','preserve', 'HeaderLines',22);
The 'Headerlines' name-value pair skips the first 22 lines, creating a useful table as ‘T1’.
To access the variables, see Access Data in Tables.
One slight complication is the first column, that requires a slight bit of effort, since the preserved variable names need to be in quotes and in parentheses:
time_ms = T1.('Time(ms)');
The others are straightforward to access:
X = T1.X;
and so for the rest.
Firefox chose to crash on me while I was writing this. My apologies for the delay.
EDIT — (24 Nov 2020 at 21:18)
In R2020a, it might be necesary to use 'PreserveVariableNames',1 instead. The result is the same, only the arguments are different.
  2 件のコメント
EW
EW 2020 年 11 月 24 日
I copied and pasted your T1 code and it did not work. But I got it to work by removing the 'VariableNamingRule' and 'preserve'.
Many thanks. I'm alot further along than I was with this help!
Star Strider
Star Strider 2020 年 11 月 24 日
As always, my pleasure!
Please note that I added the EDIT with respect to R2020a and earlier releases requiring a different name-value pair to achieve the same result.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDebugging and Analysis についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by