I have two matrix a and b, which have dimension of 241 x 360. The values from the a and b gives a mesh. How do I plot the mesh?

댓글 수: 8

Walter Roberson
Walter Roberson 2023년 10월 11일
Could you give an example of what you are hoping the output might look like?
Kiran
Kiran 2023년 10월 11일
For example, lets assume a and b are 2x2 matrix. where the elemnts values are,
a(1,1) = 0, a(1,2) = 2 , a(2,1) = 0, a(2,2) = 2
b(1,1) = 0, b(1,2) = 23 , b(2,1) = 50, b(2,2) = 50
This represents the four corner of a quadrilateral, with respective combination of indices. Like, a(1,1) and b(1,1) first corner and so on.
the cyclist
the cyclist 2023년 10월 12일
편집: the cyclist 2023년 10월 12일
OK, so for your small example, what would the output actually be? Don't worry how to calculate it. Just tell us the output result.
a = [0 2;
0 2];
b = [ 0 23;
50 50];
ab_mesh = ????
Walter Roberson
Walter Roberson 2023년 10월 12일
Are you trying to create a solid? Where the bottom is given by one of the matrices and the top is given by the other matrix, and they are assumed to be some set distance apart? If so then how do you want to handle the situation where they have different number of vertices?
Kiran
Kiran 2023년 10월 12일
The output on matlab should look like this. A grid formed using martix a and b.
Walter Roberson
Walter Roberson 2023년 10월 12일
But you asked for a mesh, and what you show is not a mesh.
Kiran
Kiran 2023년 10월 12일
Yes, but that's just for example the real matrix has dimension 241 x 55298 for a and b, so lot of points to form grid. My question was, can we get a grid in matlab if we know the elements of a and b?
Image Analyst
Image Analyst 2023년 10월 12일
@Kiran did you even see my answer from yesterday below (scroll down)?

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

 채택된 답변

Walter Roberson
Walter Roberson 2023년 10월 12일

0 개 추천

a = [0 2 3;
0 2 4];
b = [ 0 2.3 4;
5 5 3];
h = size(a,1);
w = size(a,2);
idx = reshape(sub2ind([h, w], 1:h*w), h, w);
tl = idx(1:end-1, 1:end-1);
tr = idx(1:end-1, 2:end);
ll = idx(2:end, 1:end-1);
lr = idx(2:end, 2:end);
T = [tl(:), ll(:), lr(:), tr(:)];
X = [a(:), b(:), zeros(numel(a),1)];
tetramesh(T, X)
view(2)

댓글 수: 1

The sub2ind() is not needed...
a = [0 2 3;
0 2 4];
b = [ 0 2.3 4;
5 5 3];
h = size(a,1);
w = size(a,2);
idx = reshape(1:h*w, h, w);
tl = idx(1:end-1, 1:end-1);
tr = idx(1:end-1, 2:end);
ll = idx(2:end, 1:end-1);
lr = idx(2:end, 2:end);
T = [tl(:), ll(:), lr(:), tr(:)];
X = [a(:), b(:), zeros(numel(a),1)];
tetramesh(T, X)
view(2)

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

추가 답변 (1개)

Image Analyst
Image Analyst 2023년 10월 12일

0 개 추천

Not sure what you mean by "plot" but to view a and b as 2-D images and 2.5-D surface plots:
subplot(2, 2, 1);
imshow(a, []);
subplot(2, 2, 2);
imshow(b, []);
subplot(2, 2, 3);
surf(a);
subplot(2, 2, 4);
surf(b);
Or you could simply double click on a and b in the workspace panel to bring them up in the variable editor panel in MATLAB.

댓글 수: 1

Kiran
Kiran 2023년 10월 12일
I got something like this. But, can you let me know hwo to get a 2d plot, like in the sketch?

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

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

질문:

2023년 10월 11일

댓글:

2023년 10월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by