Visualizing 1D data with Color.

40 ビュー (過去 30 日間)
MINA
MINA 2016 年 4 月 26 日
コメント済み: Kevin Moerman 2016 年 5 月 2 日
Hello,
I have a vector which gives the speed of a rat over time. Could someone please help me how I can show this data with a "color map" or "color bar". Basically I want to show each data point with a color.
Thanks

採用された回答

Kevin Moerman
Kevin Moerman 2016 年 4 月 26 日
編集済み: Kevin Moerman 2016 年 4 月 26 日
There are many different ways of doing this. It depends on how you want to visualize the data. E.g. as bars, as dots, as a 1xn surface, as a 1xn image.
If you want an image you could use the following for a vector "a":
a=rand(1,10); figure; imagesc(a); colormap(jet(numel(a))); colorbar;
Alternatively you could use the scatter function to plot as colored points. For the x coordinates you could use time and for y the speed and you can color the points according to speed e.g.:
n=10; t=1:n; a=rand(1,n); figure; scatter(t,a,50,a,'filled');colormap(jet(n)); colorbar;
  2 件のコメント
MINA
MINA 2016 年 4 月 26 日
Thanks Kevin,
That was helpful. Could you please tell me how I can change the X axis on imagesc to show the time. Thanks
Kevin Moerman
Kevin Moerman 2016 年 5 月 2 日
For images the axis units are pixels. You could however manually override the axis labels using somehting like XTickLabel (search MATLAB help for that). Alternatively you create patch type data (faces and vertices) and plot it with your own coordinates. My ind2patch function (see fileExhange) can do that (similar to surface, or pcolor commands in this case, although they assume corners of pixels are given instead of centres of pixels and therefore "take away" 1 data point).

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by