Borrar filtros
Borrar filtros

Is there a function available to import row vectors from csv file?

4 visualizaciones (últimos 30 días)
Rajesh Patel
Rajesh Patel el 9 de Oct. de 2017
Comentada: Image Analyst el 11 de Oct. de 2017
I have csv files where the data is row wise. so the vector names are in first column and data is along the row. Is there are function available to import the data in matlab. The row vector sometime can be characters or numeric data. Any help would be appreciated. Thanks
Now I have attached sample data file also

Respuestas (3)

Image Analyst
Image Analyst el 9 de Oct. de 2017
You forgot to attach the file. Failing that, all I can suggest is to try importdata() (which is pretty flexible in what it can understand), or textscan().

Rajesh Patel
Rajesh Patel el 9 de Oct. de 2017
Sorry, I have attached a sample file (I had to modify to remove confidential information). Vector names are in Column #2.
Thanks

Image Analyst
Image Analyst el 10 de Oct. de 2017
sampleData = importdata('sample.csv')
seems to work just fine. Any problem with it? If so, state what they are.
  2 comentarios
Rajesh Patel
Rajesh Patel el 11 de Oct. de 2017
I am sorry, I should have made the sample file exactly as real data file. The real data file has header information. I removed it in order to preserve the confidential information. I have created a new sample file (attached) which is nearly same as structure as the real data file. It seems that importdata is not able to import the data completely. Finally I need vectors with names in "B1:B29". I appreciate your help. Thanks
Image Analyst
Image Analyst el 11 de Oct. de 2017
importdata has a 'headerlinesIn' option where you can tell it to skip 20 lines, if there is a known number of header lines in the image. However there is a problem that you have lines like
-1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
that follow the data, and that causes it to throw an error. You might have to write a custom function that either (1) reads your code with fgetl() and textscan() to parse and convert lines of text as you go down line-by-line, or (2) read the file line-by-ling and write only the "good" data lines to a file called 'delete_me.csv' which you can then read with importdata() and delete after it's read in and you don't need it anymore.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by