How to skip last n rows while reading a csv file using readtable?

45 vues (au cours des 30 derniers jours)
Rahul Bhadani
Rahul Bhadani le 16 Fév 2021
Commenté : Walter Roberson le 22 Nov 2022
I have a csv file that I want to read as table in MATLAB using readtable command. However, I know that last few lines are corrupted or not reliable and I want to skip them. How can I do that using readtable. Note that a similar function is available in python's panda package for read.csv by supplying skipfooter.

Réponse acceptée

Rahul Bhadani
Rahul Bhadani le 16 Fév 2021
I was overthinking. It is very simple to do actually.
T= readtable(csvfile,'PreserveVariableNames',true);
n_skip = 5;
T = T(1:end-n_skip,:);
  1 commentaire
Venkatkumar M
Venkatkumar M le 22 Nov 2022
How to skip first 20 rows in the csv file?
Could you please give some answer?

Connectez-vous pour commenter.

Plus de réponses (1)

KALYAN ACHARJYA
KALYAN ACHARJYA le 16 Fév 2021
Modifié(e) : KALYAN ACHARJYA le 16 Fév 2021
This way?
data_table=readtable('filename');
%want to remove n rows from last
n=;...?
data=data_table(1:end-n,:)
  4 commentaires
Venkatkumar M
Venkatkumar M le 22 Nov 2022
How to skip first 20 rows in the csv file?
Could you please give some answer?
Walter Roberson
Walter Roberson le 22 Nov 2022
data_table = readtable('filenameGoesHere', 'HeaderLines', 20);

Connectez-vous pour commenter.

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by