필터 지우기
필터 지우기

Importing just one column from a file.

조회 수: 1 (최근 30일)
Ricardo
Ricardo 2011년 9월 22일
Hi, I have a dat. file and it has this structure:
5 2
2 4
1 1 1 1 1
2 3 4
1 0 0 3 5
1
...
and it goes on, so it´s like a lot of vectors. I need to get the values just from the "x dimension", so I need to get the first column of each vector (till the end of the matrix, each line has at least one number). I have tried lots of methods, but no one seems work.
I would appreciate if you could send me a "command name" or a link for research.
Thanks,
Ricardo.
  댓글 수: 2
Jan
Jan 2011년 9월 22일
The format of the file is not clear.
Please post what you have done and explain, which errors or problems occurred. It is much easier to fix a problem that to create a new program.
Ricardo
Ricardo 2011년 9월 22일
The fact was that I couldn´t make a single column vector of
transpose of [5 2 1 2 1 1], I have imported the data with lots of commands and I couldn´t exclude the information from further columns from the new vectors and matrices I have created.
It wasn´t like an error occuring, just an objective I wasn´t able to achieve. But Walter´s answer has already solved the problem.
Thanks for your time !!!

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2011년 9월 22일
fid = fopen('YourFile.txt','rt');
indata = textscan(fid,'%f%*[^\n]');
fclose(indata);
x = indata{1};

추가 답변 (1개)

Wayne King
Wayne King 2011년 9월 22일
Is it just numeric data without any text, or header?
If so, how about dlmread()
You can use dlmread() to read a specified range.
RESULT = dlmread(FILENAME,DELIMITER,RANGE) reads the range specified
by RANGE = [R1 C1 R2 C2] where (R1,C1) is the upper-left corner of
the data to be read and (R2,C2) is the lower-right corner. RANGE
can also be specified using spreadsheet notation as in RANGE = 'A1..B7'.
  댓글 수: 2
Wayne King
Wayne King 2011년 9월 22일
I agree with Jan about the format, looking at your example more closely -- I'm much less convince that you can identify the range.
Ricardo
Ricardo 2011년 9월 22일
Yeah, I can´t define a range, Walter´s answer really helped.
Thanks for your attention.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by