필터 지우기
필터 지우기

How to generate distincted distanced coordinates?

조회 수: 1 (최근 30일)
kahlan hasan
kahlan hasan 2022년 11월 24일
댓글: kahlan hasan 2022년 11월 25일
I would like to generate the following coordinates :
x = [0 50 100 ...1000], y=[0 50 100 ... 1000], such that the first coordinate is [x = 0 y =0], second coordinate is [x = 50 y=0], .. and so on until [x=1000 y=0] and then the same for y.
any help?

채택된 답변

Florian Bidaud
Florian Bidaud 2022년 11월 24일
x = [0:50:1000];
y = [0:50:1000];
[xGrid,yGrid] = meshgrid(x,y);
  댓글 수: 3
Florian Bidaud
Florian Bidaud 2022년 11월 25일
편집: Florian Bidaud 2022년 11월 25일
xGrid and yGrid are exactly the grid you want. I reduced the size for visibility.
x = [0:50:200];
y = [0:50:200];
[xGrid,yGrid] = meshgrid(x,y)
xGrid = 5×5
0 50 100 150 200 0 50 100 150 200 0 50 100 150 200 0 50 100 150 200 0 50 100 150 200
yGrid = 5×5
0 0 0 0 0 50 50 50 50 50 100 100 100 100 100 150 150 150 150 150 200 200 200 200 200
If you want to combine them in a cell array for example :
for i = 1:length(xGrid)
for j = 1:length(yGrid)
cellArray{i,j} = [xGrid(i,j) yGrid(i,j)];
end
end
disp(cellArray)
{[ 0 0]} {[ 50 0]} {[ 100 0]} {[ 150 0]} {[ 200 0]} {[ 0 50]} {[ 50 50]} {[ 100 50]} {[ 150 50]} {[ 200 50]} {[0 100]} {[50 100]} {[100 100]} {[150 100]} {[200 100]} {[0 150]} {[50 150]} {[100 150]} {[150 150]} {[200 150]} {[0 200]} {[50 200]} {[100 200]} {[150 200]} {[200 200]}
kahlan hasan
kahlan hasan 2022년 11월 25일
I managed to solve it, your answer helped alot, it is just i wanted it in a matrix form, thank you so much.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by