How to crop the initial values and the last values of a column

15 次查看(过去 30 天)
Hello Matlab community, I am fairly new to Matlab and to be honest haven't used it in a while. My question is quite simple, I have a column from which I want to crop the first and the last 100 values, since they represent noise from the accelerometer.
colx = readtable(table,'Range','B100:B(end-100');
I have seen matlab has this new range function, which I am trying to use.
Thank you for your help

采纳的回答

dpb
dpb 2022-4-28
The 'Range' named input parameter to readtable refers to the range of an input Excel spreadsheet and is not dynamic in its definition--the end keyword is only valid inside an array/variable reference, one of which you do not yet have at this point.
Simply read the full dataset into the table (or a variable if it is only a single sensor acceleration data, the table may be overkill) and then save the sections you want with colon addressing.
This also has the advantage you could get somewhat more creative and select the start/end points from the characteristics of the signal itself, not just a hardcoded fixed number of elements.
data=readtable('yourinputfile');
NtoKill=100; % the magic number
data=data(NtoKill+1:end-NtoKill,:); % keep those in between the magic number at first, end
  2 个评论
Sarah DS
Sarah DS 2022-4-28
编辑:Sarah DS 2022-4-28
table = readtable(fileName,'Format','auto')
colx = table(101:end-100,:);
%coly = readtable(table,'Range' )
Sir, how would I specified the column here? Becase I have X, Y and Z which I have to separate for feature extraction.
dpb
dpb 2022-4-28
编辑:dpb 2022-4-29
You can't remove rows from one variable (column) in a table; it's a rectangular structure; you keep/delete all columns by rows of the table or none.
As for referencing the data in a table, you use the "dot" notation with the defined variable names; presuming something creative like X it's simply
data.X
And, use the table reference throughout, do NOT create additional variables that are simply needless copies of the same data. The latter is a very common habit/practice of the inexperienced in thinking they have to have another variable.
See (and read) the documentation on the table class; there's a full page on addressing modes to do anything you wish/desire effectively. <Access data in table>

请先登录,再进行评论。

更多回答(1 个)

Matt J
Matt J 2022-4-28
colx=colx(101:end-100,:)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by