How to add some values between two points?

Dear everyone, Now I have some coordinates pairs and I want to add more points in the area.
For example, If I have the dataset
A = [1,2;2,2;1,3;2,3]
I want to get the matrix
B = [1, 2 ; 1.1, 2; 1, 2.1 ;1.1, 2.1; ..... ; 1.9, 2.9; 2.9, 3; 2, 2.9 ; 2, 3 ]
Thanks a lot

 Accepted Answer

In here, I didn't use any special function. but the result looks not bad
Xmin = 1;
Ymin = 2;
Xmax = 2;
Ymax = 3;
step = 0.1;
step_1 = 1/0.1;
K = (Xmax-Xmin)*(Ymax-Ymin)*step_1*step_1;
Co = zeros(K,2);
n_Co = 1;
for i = Xmin:step:Xmax
for j = Ymin:step:Ymax
Co(n_Co, 1) = i;
Co(n_Co, 2) = j;
n_Co = n_Co+1;
end
end
My result is in the following

1 Comment

Except that's not what you originally asked for. Originally you had the first column increasing every row.

Sign in to comment.

More Answers (2)

r = linspace( min(A(:,1)), max(A(:,1)), 11 );
c = linspace( min(A(:,2)), max(A(:,2)), 11 );
11 is needed instead of 10 because you need to include the final value.

1 Comment

Thanks for your quick answer. And now we get the linspace for X and Y, but I need a matrix of them as the picture shows, I want to get the values as the blue block area shows~~~

Sign in to comment.

How about this:
n = 20 % Whatever...
A = [1,2;2,2;1,3;2,3]
% Make new linearly interpolated array.
A2 = imresize(A, [n, 2])
A2 = A2(3 : end-2,:)

1 Comment

Thanks for your answer.
And I have tried your method, but the result looks a little strange
0.876250000000000 2
0.886250000000000 2
0.906250000000000 2
0.936249999999999 2
0.976250000000000 2
1.02981250000000 1.99881250000000
1.11493750000000 1.99043750000000
1.22656250000000 1.97656250000000
they are not uniform
Now I write my own code in the following answer.maybe there is a better method
Thanks a lot

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!