Create matrix from 2 columns of a csv file
조회 수: 14 (최근 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:
- Reference number (numbers - a consistant series)
- ID (a unique number)
- X, Y (Distances in a cartesia plane - upto 7 decimal points)
- Name (A string - not unique, includes numbers, letters and symbols)
- Time (a time stamp - I'd love to read it as yyyymmddhhmm, but reading it as date is also fine)
- 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
Adam Danz
2020년 12월 29일
I recommend that you don't split up the table and use table indexing instead. There's rarely a good reason to split up a tidy data set. One exception is if you're trying to reduce the size of your table in memory by eliminating variables you know you'll never need.
답변 (1개)
Adam Danz
2020년 12월 29일
Summary of comments under the question:
- Use readtable() to import the data
- Use table indexing rather than splitting the table into separate variables.
댓글 수: 2
Image Analyst
2020년 12월 29일
James, if you need more help, attach the CSV file. It's rarely / never a good idea to leave off a data file and then have people have to ask for it afterwards. So for now you'll have to live with hints and partial answers than complete turnkey solutions.
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!