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

ある変数に応じて2次元プロットの色を変更する方法を教えてください。
例えば、あるGPSの軌跡X(緯度)、Y(経度)のデータと、その時の加速度Zのデータがあります。
X,Yのデータをプロットして、走行軌跡を表示させるときに、
Zの値が+(加速)の時は赤、ー(減速)の時は青といったプロットをしたいです。
また、Zがー(減速)の時のプロットの数はいくつか、自動で算出させたいです。
初心者なので申し訳ありませんが、よろしくお願いします。

 채택된 답변

Atsushi Ueno
Atsushi Ueno 2024년 1월 26일
이동: Atsushi Ueno 2024년 1월 26일

0 개 추천

上記は説明用で、単に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

Atsushi Ueno
Atsushi Ueno 2024년 1월 26일
이동: Atsushi Ueno 2024년 1월 26일
t = 0:0.01:99.99;
x = sin(2*t);
y = cos(3*t);
z = (sin(8*t) > 0) * 2 - 1;
numel(z(z<0)) % Zがー(減速)の時のプロットの数はいくつか
ans = 4988
tiledlayout(2,2);
nexttile; scatter3(x,y,z,5,z,'filled'); view(2);
nexttile; scatter3(x,y,z,5,z,'filled'); view(3); % 右側:仕組み
colormap([1,0,0; 0,0,1]);
Kikuchi
Kikuchi 2024년 1월 26일
ありがとうございます!やりたいことが上手くできました!!
Kikuchi
Kikuchi 2024년 1월 26일
이동: Kojiro Saito 2024년 1월 27일
ありがとうございました。無事に解決できました。

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

제품

릴리스

R2021a

질문:

2024년 1월 26일

이동:

2024년 1월 27일

Community Treasure Hunt

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

Start Hunting!