color coding data points

13 ビュー (過去 30 日間)
mukesh bisht
mukesh bisht 2021 年 4 月 30 日
編集済み: Adam Danz 2021 年 5 月 1 日
I have a large matrix (Let's say 100*100). I want to plot the data and color each data point with certain color depending on its value
Please suggest a method to do this
  1 件のコメント
Mathieu NOE
Mathieu NOE 2021 年 5 月 1 日
hello
see below and attachement
x = linspace(0,40*pi,400);
y = 16+16*sin(x);
h = plot(x,y); % capture the line handle when you plot it
caxis([1 32]);
cd = colormap(jet(32)); % take your pick (doc colormap)
cd = interp1(linspace(min(y),max(y),length(cd)),cd,y); % map color to y values
cd = uint8(cd'*255); % need a 4xN uint8 array
cd(4,:) = 255; % last column is transparency
cbv=colorbar('v');
set(cbv,'YTick',[1:32],'TickLabels',cellstr(num2str((1:32)')))
drawnow
set(h.Edge,'ColorBinding','interpolated','ColorData',cd)

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

回答 (1 件)

Adam Danz
Adam Danz 2021 年 5 月 1 日
編集済み: Adam Danz 2021 年 5 月 1 日
> I want to plot the data and color each data point with certain color depending on its value
That's what scatter or scatter3 is designed for. You can set the color of each point.
Alternatively, you could use imagesc(C) where C is your matrix or heatmap.
See the documentation and if you have any trouble implementing your figures based on the examples in the documentation, show us what you've got and describe where you're stuck.

カテゴリ

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