- Longitude and Latitude Conversion: The conversion you're applying to the user-provided longitude and latitude seems incorrect. Usually, you don't need to add or subtract anything from the user-provided values unless you're trying to match them to a specific format or range used in your data. Most geographic datasets use longitude values ranging from -180 to 180 degrees and latitude values from -90 to 90 degrees, which matches the range you're checking for user input. So, you likely don't need to adjust these values for plotting.
- Plotting on a Map: You're using surf and imagesc functions, which suggests you're trying to plot data on a 2D map. However, the use of both might not be necessary or might be causing the "funny" look, depending on how map2 and map are defined (which isn't clear from the provided code). Typically, for plotting geographic data, you might want to stick with one method that best represents your data. If map2 is a 2D matrix of wave heights, using imagesc with proper latitude and longitude bounds might be sufficient.
- Incorrect Variables for imagesc: You're using ocean_long and ocean_latitude with imagesc, but these variables haven't been defined earlier in the provided code snippet. Perhaps you meant to use longitude_index and latitude_index?
- Plotting the User's Location: When plotting the user's location, ensure that the point's coordinates are within the range and format of the underlying map's coordinates.
how can i plot user specific input by inputing latitude and longitude on an already existing plot of waveheight, latitude and longitude.
1 次查看(过去 30 天)
显示 更早的评论
I am trying to write a script that plots user specific input of latitude and longitude on an already existing plot of longitude, latitude and wave height. Here is the code:
filename2 = 'F:\Power_Config_Climate_Data\Global\NC Files\NEW_NC_FILES\2009-ocean.nc';
time_index = ncread(filename2,'time');
latitude_index = ncread(filename2,'lat');
longitude_index = ncread(filename2,'lon');
Ulongitude = input ('please enter your desired longitude : ');
Ulatitude = input ( 'please enter your desired latitude : ');
if Ulongitude < 180 && Ulongitude > -180 && Ulatitude < 90 && Ulatitude > -90
longitude = 360 + Ulongitude;
latitude = 180 + Ulatitude;
surf(longitude_index,latitude_index,map2);
imagesc(ocean_long,ocean_latitude,map);
view(2)
hold on
plot(longitude,latitude,'r*');
hold off
else
disp('unknown location');
end
the code does plot a location but it looks funny. any suggestions?
0 个评论
回答(1 个)
Pratyush
2024-4-19
Hi Alex,
You can consider making these changes in your code:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Geographic Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!