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

2 ビュー (過去 30 日間)
Shujaa 2022 年 12 月 16 日
コメント済み: Adam Danz 2022 年 12 月 20 日
"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 件のコメント3 件の古いコメントを表示3 件の古いコメントを非表示
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 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.

サインインしてコメントする。

### カテゴリ

Help Center および File Exchange3-D Visualization についてさらに検索

### Community Treasure Hunt

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

Start Hunting!