How to add some values between two points?

조회 수: 5 (최근 30일)
HONG CHENG
HONG CHENG 2017년 9월 20일
댓글: Image Analyst 2017년 9월 20일
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

채택된 답변

HONG CHENG
HONG CHENG 2017년 9월 20일
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
Image Analyst
Image Analyst 2017년 9월 20일
Except that's not what you originally asked for. Originally you had the first column increasing every row.

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

추가 답변 (2개)

Walter Roberson
Walter Roberson 2017년 9월 20일
편집: Walter Roberson 2017년 9월 20일
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
HONG CHENG
HONG CHENG 2017년 9월 20일
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~~~

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


Image Analyst
Image Analyst 2017년 9월 20일
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
HONG CHENG
HONG CHENG 2017년 9월 20일
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

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by