The problem is the following: I have a .txt file containing 3 columns of numbers. The first 2 columns are the coordinate x,y of the points. The third columnn (z vector) is made of numbers that express the luminosity of each point. (The .txt files have been generated by a software that is used to study the pictures of a combustion process). Each vector (x,y,z) is made of 316920 elements (all integer numbers). Now: is there a way to create from these 3 vectors an image in matlab relating the luminosity value to the coordiantes of the point? Thanks for your time!
-
1A matrix is an image, an image is a matrix. Can you desribe your problem better? Is the problem that your x,y points are not ordered? If so, do you have a mesh of all points (i.e. do all combination of x-y exist)? are they integers or floats? Please read [ask] and [mcve] – Ander Biguri May 08 '17 at 15:08
-
the points (x,y) are ordered. The numbers are all integer numbers. (x,y,z all integers).The matrices are rectangular – Lamberto May 09 '17 at 09:45
-
Then check the duplicates, you have your solution there. – Ander Biguri May 09 '17 at 09:51
2 Answers
consider a file image.txt contains y x and intensity values separated line. like this.
1 1 0
1 2 12
1 3 10
....
....
255 255 0
open the text file using fopen function
fid = fopen(image.txt,'r');
im=[];
and read a string-line of characters by fgetl function, convert string-line into vector using sscanf and put intensity value into y and x coordinates of a image matrix, im.
tline=fgetl(fid) ;
rd=sscanf(tline,'%d');
im(rd(1),rd(2))=rd(3);
The same process is iterated up-to end of file. at last close file-handle fid

- 13
- 3
-
-
yes.. fid represents file handle, image.txt -> file to be read and 'r' -> represents file read operation. – clcoder May 08 '17 at 16:02
-
@ Clcoder i meant image.txt should declared as string like this 'image.txt' – Reflection May 08 '17 at 16:03
-
-
dude that is what i said, i did not know this symbol's name is quote, you didn't enclosed image.txt by quote – Reflection May 08 '17 at 16:10
-
I am going to assume that the three columns in your text file are comma separated( The code will need to be a bit different if they are not comma separated) . Since you said all numbers are integers, I am going to assume that you have all the data needed to fill a 2D grid using your x and y coloumns is present. I am not assuming that it is in a ordered form. With these assumptions the code will look like
data = csvread(filename)
for i=1:length(data)
matrix(data(i,2)+1,data(i,1)+1)=data(i,3) // +1 is added since there maybe a index starting from 0 and matlab needs them to start from 1
end
image(matrix)
For other delimiters use
data = dlmread(filename,delimiter)

- 439
- 6
- 13