Filter löschen
Filter löschen

Create mesh from matrix

2 Ansichten (letzte 30 Tage)
Kiran
Kiran am 11 Okt. 2023
Kommentiert: Walter Roberson am 13 Okt. 2023
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 Kommentare
Kiran
Kiran am 12 Okt. 2023
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 am 12 Okt. 2023
@Kiran did you even see my answer from yesterday below (scroll down)?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 12 Okt. 2023
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 Kommentar
Walter Roberson
Walter Roberson am 13 Okt. 2023
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)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 12 Okt. 2023
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 Kommentar
Kiran
Kiran am 12 Okt. 2023
I got something like this. But, can you let me know hwo to get a 2d plot, like in the sketch?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by