how to read a .txt file in matlab ?
이전 댓글 표시
i want to read a file name is imData.txt which has 9600 arbitrary float numbers. and store in array of size 80*120 after read i want show image of that array??
댓글 수: 6
Walter Roberson
2013년 7월 5일
What is the format of the data in the file? How many values are on each line of the file ?
preet
2013년 7월 5일
preet
2013년 7월 5일
Walter Roberson
2013년 7월 5일
Is there exactly one float value per row? Are there exactly 80 float value per row? Exactly 120? Is everything in one large column?
Is the second value in the file to become matrix location (2,1) or matrix location (1,2) ?
Are the columns delimited by spaces? By tabs? Is there a fixed width for each column and the columns can "run together" because of that?
What are the minimum and maximum values in the file?
preet
2013년 7월 6일
preet
2013년 7월 6일
채택된 답변
추가 답변 (2개)
Sivakumaran Chandrasekaran
2013년 7월 4일
0 개 추천
use textread command
Hugo
2013년 7월 6일
0 개 추천
Suppose that your file is called data.txt You can load the data simply with
load('data.txt');
which will create a variable called "data"
and the print it using
imagesc(data)
댓글 수: 4
preet
2013년 7월 6일
preet
2013년 7월 6일
preet
2013년 7월 6일
Hugo
2013년 7월 6일
If I understood right, you said that the values are in matrix form in the file. That should mean that your file is structures as lines ending in a newline symbol, and each number in each line is separated by a space. If that's the case, no matter whether the numbers are integer or real, load(...) will give you a matrix with as many rows as lines in the file and as many columns as numbers in the line, provided the number of numbers is the same in each line.
Once this is solve, I don't know what your values represent. If the position in the matrix represents the position of the pixels and the value represents the colour, then image(...) should show the image. Otherwise, I think it's up to you what you really have and how you really want to represent it.
I hope this helps you. Good luck.
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!