How do I plot three variables against each other?

I have a list of lightning flahses, each flash has a latitude, longitude, and a power. All three of these are lists, not matrices.
I would like to plot a 3D plot, where x is longitude, y is latitude, and each dot is color coded to represent its power at the latitude and longitudinal locations.
How do I do this using three lists? The 3d plotting functions, like imagesc, require a matrix as the third value.
Thanks!

 採用された回答

Star Strider
Star Strider 2019 年 6 月 28 日

0 投票

Try this:
lat = rand(10,1); % Create Vector
lon = rand(10,1); % Create Vector
power = randi(9,10,1); % Create Vector
figure
scatter3(lat(:), lon(:), power(:), [], power(:), 'filled')
grid on
This will colour them by the ’Z’ (’power’) value. The fourth argument [] is the size reference, and since you may want them all the same size, that argument is the empty array.

6 件のコメント

Sophia Salazar
Sophia Salazar 2019 年 6 月 28 日
It produced this error: Error in color/linetype argument.
Star Strider
Star Strider 2019 年 6 月 28 日
It works with simulated data in R2019a.
I would have to see at least a representative sample of your data to see what the problem is.
What version of MATLAB are you using?
Sophia Salazar
Sophia Salazar 2019 年 6 月 28 日
R2018b. I copied and pasted your code into my command window and it worked, but I am not sure why my code doesnt. Latitude, Longitude, and PeakCurrentQuarter are all 393413x1 double.
figure(5); clf;
hold on
scatter3(Latitude(:), Longitude(:), PeakCurrentQuarter(:), [], PeakCurrentQuarter(:), 'filled ')
grid on
hold off
Star Strider
Star Strider 2019 年 6 月 28 日
I tried my code with vectors of your size data, and even using randn for the ‘power’ vector to see if negative values could be the problem. It worked (including the colour mapping) with all of those, and ran without error.
Something is wrong somewhere, and it seems to be with your variables.
Run the whos function with your variables, and post back the result:
whos('lat','lon','power')
This is just an example, use the variable names you are using in your code.
It is also possible that you are not using the latest MATLAB updates. See: 2018b Update 3 for the update procedure.
Sophia Salazar
Sophia Salazar 2019 年 6 月 28 日
Name Size Bytes Class Attributes
Latitude 393413x1 3147304 double
Longitude 393413x1 3147304 double
PeakCurrentQuarter 393413x1 3147304 double
Star Strider
Star Strider 2019 年 6 月 28 日
I have no idea what the problem could be.
I would need at least a representative sample of your data to see what the problem is (assuming I could reproduce it).

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGeographic Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by