Coordinates of each rectangular cell is required

I have created a mesh using mesh command having 16 cells.
I want the coordinates of every cell in a separate array.I had tried the following code but it didnot work.Please help.
x=zeros(1,5)+5;
y=linspace(4,16,5);
xx=x';
yy=y';
[XX,YY]=meshgrid(xx,y);
Y=YY';
z=linspace(-1,3,5)';
zz=repmat(z,1,5);
A=mesh(XX,Y,zz);
axis([-10 40 -10 40])
for a=1:4
for b=1:4
C1X1(a,b)=[XX(a,b) XX(a,b+1) XX(a+1,b) XX(a+1,b+1)];
end
end
C1X1 should be 16 by 4 matrix as the loop runs 16 times but I am unable to define C1X1

 採用された回答

Dyuman Joshi
Dyuman Joshi 2021 年 11 月 29 日

1 投票

You are defining C1X1 incorrectly (trying to fit 4 elements as 1) -
x=zeros(1,5)+5;
y=linspace(4,16,5);
xx=x';
yy=y';
[XX,YY]=meshgrid(xx,y);
Y=YY';
z=linspace(-1,3,5)';
zz=repmat(z,1,5);
A=mesh(XX,Y,zz);
axis([-10 40 -10 40])
C1X1=[];
for a=1:4
for b=1:4
C1X1=[C1X1; XX(a,b) XX(a,b+1) XX(a+1,b) XX(a+1,b+1)];
end
end
C1X1
C1X1 = 16×4
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5

5 件のコメント

MD EQBAL
MD EQBAL 2021 年 11 月 30 日
編集済み: MD EQBAL 2021 年 11 月 30 日
Thanks a lot.
Can you please guide me about the purpose of C1X1=[]; ?
Dyuman Joshi
Dyuman Joshi 2021 年 11 月 30 日
It defines C1X1 as an empty matrix. We can modify it however we want to.
MD EQBAL
MD EQBAL 2021 年 11 月 30 日
編集済み: MD EQBAL 2021 年 12 月 1 日
Thanks a lot.
Can you guide me in one more problem?
If A is rotated by 10 degrees, how can I find the new coordinates of the new rectangular cell?
x=zeros(1,5)+5;
y=linspace(4,16,5);
xx=x';
yy=y';
[XX,YY]=meshgrid(xx,y);
Y=YY';
z=linspace(-1,3,5)';
zz=repmat(z,1,5);
A=mesh(XX,Y,zz);
direction = [0 0 1];
centre=[25 10 1];
rotate(A,direction,10,centre)
Dyuman Joshi
Dyuman Joshi 2021 年 11 月 30 日
What do you mean by rotated by 10 degrees?
MD EQBAL
MD EQBAL 2021 年 12 月 1 日
By rotation of 10 deg, I mean that the mesh A is rotated by 10 degrees about an axis passing through its centre and parallel to z axis.
After rotation, the coordinates of the rectangular cell will change. I was trying to assign another variable B to the rotated mesh like this:-
B=rotate(A,direction,10,centre)
But the following error occurs :-
" Error using rotate
Too many output arguments."
I need the coordinates of the rectangular cell of the rotated mesh.
Please help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGeometric Transformation and Image Registration についてさらに検索

質問済み:

2021 年 11 月 29 日

コメント済み:

2021 年 12 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by