Filter löschen
Filter löschen

Get a three column matrix from meshgrid data

15 Ansichten (letzte 30 Tage)
Sk Zeeshan Ali
Sk Zeeshan Ali am 20 Jan. 2020
Beantwortet: Star Strider am 20 Jan. 2020
I have the following program:
x=linspace(0.1,0.3,3);
y=linspace(1,3,3);
[x1,y1] = meshgrid(x,y);
z=x1.*y1;
Now I want to rearrange the data to get a three column matrix C like this
0.1 1 z1
0.1 2 z2
0.1 3 z3
0.2 1 z4
0.2 2 z5
0.2 3 z6
0.3 1 z7
0.3 2 z8
0.3 3 z9
where z1 to z9 are the corresponding values. So, how to obtain the above matrix?

Akzeptierte Antwort

Star Strider
Star Strider am 20 Jan. 2020
Add one line:
x=linspace(0.1,0.3,3);
y=linspace(1,3,3);
[x1,y1] = meshgrid(x,y);
z=x1.*y1;
C = [x1(:), y1(:), z(:)]
to produce:
C =
0.1 1 0.1
0.1 2 0.2
0.1 3 0.3
0.2 1 0.2
0.2 2 0.4
0.2 3 0.6
0.3 1 0.3
0.3 2 0.6
0.3 3 0.9
The ‘(:)’ subscripting convention forces a column vector.

Weitere Antworten (0)

Kategorien

Mehr zu Computational Geometry finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by