- The variables "lat" and "lon" are scalars. When you use the "meshgrid" function with scalars as inputs, it creates a single x-y coordinate, not the grid that is required to plot a surface using the "surf" function.
- The function surf(X,Y,Z) generates a three-dimensional surface plot. The function plots the values in matrix "Z" as heights above a grid in the x-y plane defined by "X" and "Y".
How I can bring a specific scenerio of 3D map in matlab?
2 ビュー (過去 30 日間)
"I am trying to create a 3D map in Matlab for a simulation. I have a dataset with latitude, longitude, and altitude values, and I want to use the mesh function to plot the surface. However, I am getting an error message that says 'Z must be a matrix, not a scalar or vector'. How can I fix this error and create the 3D map using my dataset?"
% Define the latitude and longitude
viewer = siteviewer("Buildings","chicago.osm"); #How can i modify this commond and write it my own wish?
lat = [35.339444 ];
lon = [75.541389];
% Define the altitude data
alt = [1000 2000 3000 4000 5000];
% Create a grid of points using the meshgrid function
[Lon,Lat] = meshgrid(lon,lat);
% Create the 3D map using the surf function and geoshow
geoshow('landareas.shp', 'FaceColor', [0.5 0.7 0.5])
Santosh Fatale 2022 年 12 月 20 日
I understand that you want to create a 3-D map in MATLAB and have a dataset with latitude, longitude, and altitude values to plot this 3-D map.
You tried to use the "surf" function but encountered an error. I investigated the code shared by you, and the following are my observations and comments:
Note that matrix "Z" has a value for each grid value in "X" and "Y", and the dimensions of X, Y, and Z are the same.
To make a 3D plot using a longitude, latitude, and altitude data set, you need to create an altitude matrix (matrix Z) for each possible pair of longitude and latitude. Once you create an altitude matrix, you can use it as matrix Z in the "surf" function. The longitude (matrix X) and latitude (matrix Y) matrices can be created using the "meshgrid" function.