This is a short tutorial on the purpose of meshgrid in Matlab.
Very simple introduction to meshgrid
In simple terms we want to get all the possible conbinations of x,y into a form known as X,Y
In the example below we have x as a 1*6
and y as a 1*5
We cannot multiply them as they are not not same size and nor can we do dot multiply i.e element by element multiplication.
Tidy up
clc
clear all
close all
Start the program
% problem we want to get every possible combination
% of x and y as laid out below
x = -2:3
x = 1×6
-2 -1 0 1 2 3
y = 4:8
y = 1×5
4 5 6 7 8
Get all the meshgrid
% X is a 5*6 ie 6 rows of -2 to + 3 inclusive
% Y is 5*6 i.e 6 columns of 4 to 8 inclusive
[X,Y] = meshgrid(x,y)
X = 5×6
-2 -1 0 1 2 3
-2 -1 0 1 2 3
-2 -1 0 1 2 3
-2 -1 0 1 2 3
-2 -1 0 1 2 3
Y = 5×6
4 4 4 4 4 4
5 5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7
8 8 8 8 8 8
as X and Y are both 5*6 we can now perform a dot multiply
% to a do multiply
F = X.*Y
F = 5×6
-8 -4 0 4 8 12
-10 -5 0 5 10 15
-12 -6 0 6 12 18
-14 -7 0 7 14 21
-16 -8 0 8 16 24
29 ноя 2021