Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip a column using txt2mat

Tags:

matlab

I´m trying to import some csv files in matlab, but csvread is too slow.

I´m using txt2mat, but i don´t know how to skip the first column in the import.

This is the way im trying

    myimportedfile = txt2mat(myfile,'ReadMode','block',1) %im skipping the headers too.

The reason i need to skip is beacause the first column is non-numerical data.

Is there a way to do this with txt2mat or is there a better way?

Tks in advance.

like image 601
Leonardo Hermoso Avatar asked Nov 26 '25 00:11

Leonardo Hermoso


1 Answers

textscan gives you the ability to skip columns. It reads in data using an fprintf-like format string.

Example file:

Val1 Val2 Val3
1    2    3
4    5    6
7    8    9

Code:

tmp = textscan('example.txt', '%i %*i %i') % the * indicates fields to ignore
tmp{:}
like image 141
Gordon Bean Avatar answered Nov 28 '25 15:11

Gordon Bean