필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How can I import a file that includes both string and numerical data?

조회 수: 1 (최근 30일)
John Harry
John Harry 2016년 8월 15일
마감: MATLAB Answer Bot 2021년 8월 20일
Hello, All. I have a data set that has 5 rows of string data and all of the remaining data are numeric. I want to import the file while maintaining only the second row of data and all the data starting at row six and after. I really just need an output with the headers (:,second column) and another output with the data (:,6:end). Is there a way to do this simply? I have looked through other posted questions but I cannot get this to work for my purpose.
Thanks!

답변 (2개)

Swarooph
Swarooph 2016년 8월 15일
Hello John,
There are a few things conflicting about your question. You first say you have 5 rows of string data and then you say extract the second row and all the rows from 6 till the end. Then in your code, you are showing this with columns and not rows..
In any case, have you looked at the import tool available in MATLAB? Take a look at this documentation. You can do this interactively using the tool. If you wanted to do this using MATLAB code, you can also generate code from this tool and use it with the same file or similar files later.
  댓글 수: 1
John Harry
John Harry 2016년 8월 15일
Thanks, Swarooph.
What I meant was that I want to keep the second row (and all the columns) in addition to all of the rows and columns starting at the 6th row. I see the error in my original post where I switched the rows/columns. Thanks for catching that. I will look into the documentation you provided. Let me know if you have any other solutions that might work for me.
Best,

Azzi Abdelmalek
Azzi Abdelmalek 2016년 8월 15일
fid=fopen('file.txt')
s=textscan(fid,'%s','headerlines',1,'delimiter','\n')
fclose(fid)
out=[s{:}]
out=out([1 5:end])
  댓글 수: 1
John Harry
John Harry 2016년 8월 15일
Azzi,
Thanks for the code. When I used your code, the variable "out" returned only column of data that appears to be columns 1 and two from the text file extracted together in a single column. I would like to return all the columns in the file. Is there a way to do that using your code?
Thanks!

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by