Plot matrix as scatter points with colorbar

1 回表示 (過去 30 日間)
Shan  Chu
Shan Chu 2018 年 10 月 3 日
コメント済み: Star Strider 2018 年 10 月 3 日
Dear all
I have a vector 1-by-N x, a vector 1-by-M y, and a matrix N-by-M z (complex).
So how could I plot the matrix Z as scatter points corresponding to x and y, where the colorbar represents the abs(z). I have tried scatter3 but it only works when z is a vector, not a matrix. Thanks

採用された回答

Star Strider
Star Strider 2018 年 10 月 3 日
One approach is to use meshgrid to create matrices out of ‘x’ and ‘y’, then plot all of them as vectors, using the (:) subscript notation to force them all to become column vectors:
N = 5;
M = 8;
x = 1:N;
y = 1:M;
[X,Y] = meshgrid(x,y);
z = randn(N,M) + 1j*randn(N,M);
figure
scatter3(X(:), Y(:), abs(z(:)), 25, abs(z(:)), 'filled', 'Marker','p')
colormap(jet(numel(z)))
colorbar
Experiment to get the result you want.
  2 件のコメント
Shan  Chu
Shan Chu 2018 年 10 月 3 日
Thank you sir. I didn't know the trick (:) to force them to all become column vectors. Brilliant
Star Strider
Star Strider 2018 年 10 月 3 日
As always, my pleasure.
Thank you.
Using the reshape function also would work. The (:) notation is easier and more efficient.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by