Create matrix from 2 columns of a csv file

28 次查看(过去 30 天)
James
James2020-12-29
评论: James ,2020-12-30
A CSV file includes all my data in seperate columns and I'm trying to extract them separately for analysis. I'm using MATLAB R2019b, btw.
CSV file looks like the one that I've attached below (Please let me know if an actual csv is needed), it contains following information:
  1. Reference number (numbers - a consistant series)
  2. ID (a unique number)
  3. X, Y (Distances in a cartesia plane - upto 7 decimal points)
  4. Name (A string - not unique, includes numbers, letters and symbols)
  5. Time (a time stamp - I'd love to read it as yyyymmddhhmm, but reading it as date is also fine)
  6. A, B, C, D (numbers - includes decimals)
I can read the data and create the matrix that include all the columns using readmatrix and I can get specific parts from that matrix. But I want to read the CSV file and create separate matrices using separate columns.
For example:
matrix_1 = matrix that includes all data in columns ID and A
matrix_2 = matrix that includes all data in columns ID, X and Y and so on.
How can I approach this, while preserving the data types included in csv? Apologies if my question needs more clarification.
  4 个评论
James
James 2020-12-29
Thanks, Adam! That's actually a good point. I was going to try creating different matrices but I'm realizing now that I can just use the table instead. Thanks for the advice!

请先登录,再进行评论。

回答(1 个)

Adam Danz
Adam Danz 2020-12-29
Summary of comments under the question:
  1. Use readtable() to import the data
  2. Use table indexing rather than splitting the table into separate variables.
  2 个评论

请先登录,再进行评论。

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by