필터 지우기
필터 지우기

Info

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

How can I read a data, in a txt file, as a matrix?

조회 수: 1 (최근 30일)
Sezin Koktas
Sezin Koktas 2020년 7월 29일
마감: MATLAB Answer Bot 2021년 8월 20일
I am working on a deep learning project and for the first step, I need to read a txt file as a matrix so that I can reach every features easily.
I have 90 classes and 42 features for each of them:
{feature1, feature2, ..., feature42}
{feature1, feature2, ..., feature42}
......
{feature1, feature2, ..., feature42}
The features starts after the keyword '@DATA' in the txt file
I can read the first row with this one. Since the keyword '@DATA' starts at line 47, I am reading the line 48. For sure, I also need to read the other lines until the end of the file. However, before that, I tried to see whether I can read the first row correctly or not.
% open the file
fid=fopen('BlindAllFeatures.txt');
% set linenum to the desired line number that you want to import
linenum = 48;
% use '%s' if you want to read in the entire line or use '%f' if you want to read only the first numeric value
C = textscan(fid,'%s',1,'delimiter','\n', 'headerlines',linenum-1);
But I am getting a 1x1 cell that has the whole {feature1, feature2, ..., feature42} when I run this code. You can see it from the image I uploaded. I need 90 rows and 42 columns but I couldn't do that. If I can do that, I will try to train them by trying different classifiers and after that, I will move on to feature selection part. I hope you can help me. Thank you.

답변 (1개)

Maria
Maria 2020년 7월 29일
Try using strplit on the C array that you got.
C = strsplit(C,', ')
  댓글 수: 2
Sezin Koktas
Sezin Koktas 2020년 7월 29일
It says:
Error using strsplit (line 80)
First input must be either a character vector or a string scalar.
Error in Feature (line 57)
C = strsplit(C,', ')
Sezin Koktas
Sezin Koktas 2020년 7월 29일
Now it is giving this,
Error using strsplit (line 91)
The delimiter must be either a character vector, a cell array of character vectors, or a string array.
Error in Feature (line 57)
C = strsplit(',',C);

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by