How I can bring a specific scenerio of 3D map in matlab?

7 次查看(过去 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
figure
surf(Lon,Lat,alt)
geoshow('landareas.shp', 'FaceColor', [0.5 0.7 0.5])
  4 个评论
Shujaa
Shujaa 2022-12-20
Hi Santosh Fatale,
I didn't used the bold format? Yes i highlight here in bold?
Adam Danz
Adam Danz 2022-12-20
I edited your question to format the code which may have removed text in bold.
See @Santosh Fatale's answer for guidance.

请先登录,再进行评论。

采纳的回答

Santosh Fatale
Santosh Fatale 2022-12-20
Hi Shujat,
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:
  • 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".
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.
Refer to the documentation of the "meshgrid" and "surf" functions for more information and illustration examples.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by