Reading data from a text file, comma delimited
조회 수: 69 (최근 30일)
이전 댓글 표시
Hi
I want to read data from a textfile, any help will be nice.
The actual data looks like this.
A B
1, 2
3, 4
5, 6
7, 8
But in the text file the data looks like this: 1, 23, 45, 67, 8
how do i read it so that i store 1 3 5 7 in A without the commas and 2 4 6 8 in B without commas.
Thanks.
댓글 수: 0
답변 (1개)
Adam Danz
2018년 8월 17일
편집: Adam Danz
2018년 8월 17일
readtable() seems to work with your example data.
m = readtable('test.txt')
m =
4×2 table
A B
_ _
1 2
3 4
5 6
7 8
m.A is your first column.
m.B is your second column.
If the first row of your data, "A B", really isn't separated by a comma, you'll lose those variables names in your table (m.Var1 instead of m.A). If they do have a comma, your table will contain the variable names. I put a comma in your example to produce my outputs.
댓글 수: 8
Adam Danz
2018년 8월 18일
Is this the best way to do what?
What do you mean "A is real, B is img"?
This seems far from your original question so maybe it would be better to post a new question for fresh eyes.
Curly brackets { } are used to index cell arrays while parentheses ( ) can be used to index matrices.
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!