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

9 visualizzazioni (ultimi 30 giorni)
"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 Commenti
Shujaa
Shujaa il 20 Dic 2022
Hi Santosh Fatale,
I didn't used the bold format? Yes i highlight here in bold?
Adam Danz
Adam Danz il 20 Dic 2022
I edited your question to format the code which may have removed text in bold.
See @Santosh Fatale's answer for guidance.

Accedi per commentare.

Risposta accettata

Santosh Fatale
Santosh Fatale il 20 Dic 2022
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.

Più risposte (0)

Categorie

Scopri di più su Geographic Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by