MATLAB Answers

How to extract text and value from a .txt file ?

43 views (last 30 days)
Karim
Karim on 29 Sep 2017
Commented: Karim on 3 Oct 2017
Hi,
i have to import an array from a .txt file into Matlab. The problem is I have 2 arrays of similar shape that contain text and numbers (I would like both).
I tried using "uiimport" (which is convenient since I'm making a GUI): It works well with the file1 : I get a "data" matrix (I don't know what it is) and a "textdata" cell array which I can work with.
However here is the problem, with the file2, the "textdata" cell array only contains the first line.
Could you please help me find a solution ?
(I suggest the problem may be related to the last column being empty)

  7 Comments

Show 4 older comments
Guillaume
Guillaume on 29 Sep 2017
@Kian, use the answer box for answers, rather than comments on the question.
That way, you'll get reputation points if Karim accepts your answer. He can't do that with comments.
Kian Azami
Kian Azami on 2 Oct 2017
@Guillaume thank you for your comment. I didn't know it. For the next times I will answer the questions instead of put a comment.
Karim
Karim on 3 Oct 2017
Thank you for your help, this helped me to resolve my problem.

Sign in to comment.

Accepted Answer

aL
aL on 29 Sep 2017
You can use the readtable command.
filedata = readtable('file2.txt','delimiter','\t','readvariablenames',true);

  1 Comment

Sign in to comment.

More Answers (0)

Sign in to answer this question.


Translated by