変数に応じてplotの色を変更する方法

21 visualizzazioni (ultimi 30 giorni)
Kikuchi
Kikuchi il 26 Gen 2024
Spostato: Kojiro Saito il 27 Gen 2024
ある変数に応じて2次元プロットの色を変更する方法を教えてください。
例えば、あるGPSの軌跡X(緯度)、Y(経度)のデータと、その時の加速度Zのデータがあります。
X,Yのデータをプロットして、走行軌跡を表示させるときに、
Zの値が+(加速)の時は赤、ー(減速)の時は青といったプロットをしたいです。
また、Zがー(減速)の時のプロットの数はいくつか、自動で算出させたいです。
初心者なので申し訳ありませんが、よろしくお願いします。
  2 Commenti
Dyuman Joshi
Dyuman Joshi il 26 Gen 2024
Could you please show what you have tried yet?
Also, do you want a scatter plot or a line plot?

Accedi per commentare.

Risposta accettata

Atsushi Ueno
Atsushi Ueno il 26 Gen 2024
Spostato: Atsushi Ueno il 26 Gen 2024
上記は説明用で、単に2次元でプロットしたいなら下記でOKです。
t = 0:0.01:99.99;
x = sin(2*t);
y = cos(3*t);
z = (sin(8*t) > 0) * 2 - 1;
scatter(x,y,5,z,'filled');
colormap([1,0,0; 0,0,1]);
  3 Commenti
Kikuchi
Kikuchi il 26 Gen 2024
ありがとうございます!やりたいことが上手くできました!!
Kikuchi
Kikuchi il 26 Gen 2024
Spostato: Kojiro Saito il 27 Gen 2024
ありがとうございました。無事に解決できました。

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!