hi everybody , i have a question please , if i have X=[1:10] and Y=[-5:5] and i want to have all the point of the plane (x,y) , what can i do in matlab to extract this point to use it
1 回表示 (過去 30 日間)
古いコメントを表示
X=[1:10];
Y=[-5:5];
for i=1:10
for j=1:10
3 件のコメント
採用された回答
James Tursa
2019 年 2 月 25 日
編集済み: James Tursa
2019 年 2 月 25 日
Does this do what you want?
[x,y] = meshgrid(X,Y);
result = [x(:),y(:)];
Then iterate over the rows of result.
Or you can just use your double for loop, and have
for i=1:numel(X)
for j=1:numel(Y)
point = [X(i),Y(j)];
etc.
6 件のコメント
James Tursa
2019 年 2 月 27 日
You didn't pre-allocate TgT to the dimensions I specified. You have this:
TgT=zeros(length(x),length(y))
But I have this:
tgt = zeros(numel(x)*numel(y),2);
Jan
2019 年 2 月 27 日
編集済み: Jan
2019 年 2 月 27 日
@mina: "it didnt work" is not useful to explain a problem. Do you get an error message (than post a complete copy) or do the result differ from your expectation (then explain both).
clear all; clc is called "cargo cult programming": It does not help to solve any problem. All it does is to waste processing time here.
A simpler method instead of the loops:
x = 0:intx:D_x; % No need for brackets
y = -D_y/2:inty:D_y/2; % x and y are vectors already
nx = numel(x);
ny = numel(y);
TgT = [replem(x.', ny, 1), repmat(y.', nx, 1)];
その他の回答 (1 件)
madhan ravi
2019 年 2 月 25 日
I am not sure I fully understand but see if it does what you want
[x,y]=ndgrid(X,Y);
[x(:) y(:)] % after this it’s just matrix manipulation
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!