How to crop the initial values and the last values of a column
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponse acceptée
dpb
le 28 Avr 2022
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 commentaires
dpb
le 28 Avr 2022
Modifié(e) : dpb
le 29 Avr 2022
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>
Plus de réponses (1)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!