matlab - Setting a matrix to one on a list of incomplete rectangular grid points -


i have set of data in text file shows coordinates of rectangular grid in size of 81x61. each row shows longitude , latitude of grid point. longitudes change 50.00 80.00 (61 values), , latitudes change 30.00 70.00 (81 values) in order this:

50.00  30.00 51.50  30.00 52.00  30.00 . . . 79.50  30.00 80.00  30.00 50.00  31.00 50.50  31.00 51.00  31.00 . . . 79.00  70.00 79.50  70.00 80.00  70.00 

i have text file consists of random coordinates rectangular grid mentioned above.

i want create matrix of size 81x61 elements of 0 , 1 in way 1s correspond coordinates second text file.

how can write code in matlab?


example of need in small scale:

text file:

  1  1   1  2   1  3   .   .   .   4  3   4  4   4  5  

corresponding rectangular grid of above text file:

1,1  1,2  1,3  1,4  1,5 2,1  2,2  2,3  2,4  2,5 3,1  3,2  3,3  3,4  3,5 4,1  4,2  4,3  4,4  4,5 

2nd text file:

1  1 1  3 2  4 2  5 3  4 4  1 4  5   

corresponding matrix of above text file:

1  0  1  0  0 0  0  0  1  1 0  0  0  1  0 1  0  0  0  1 

i want create matrix of size 81x61 elements of 0 , 1 in way 1s correspond coordinates second text file.

that's relevant information in question. answer matlab function sub2ind(documentation). converts list of x, y coordinates list of array indices can conveniently set one.

suppose have read content of second file in nx2 matrix called second_file , size of result matrix have given in variable matrix_size (81x61). do:

x = second_file(:, 1); y = second_file(:, 2); result = zeros(matrix_size); index = sub2ind(matrix_size, x, y); result(index) = 1; 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -