Colorbar with a range taken from a variable

Hello,
I have a matrix organized in this way:
M= col1, col2.... col10
col1 and col2 are the x and y position of the data, col10 is a property of this data and it is a number.
I would like to use the numbers in col10 to make a colormap and assign ot every point a specific color that depends on the value in col10.
I did this long time ago, but I don't remember how, can somebody help me, please?
Thanks
F.

 채택된 답변

Star Strider
Star Strider 2024년 8월 5일
I am not certain what plot you want to use or what result you want.
Perhaps something like this —
x = linspace( 0, 5);
y = linspace(-5, 5);
z = exp(-((x-2.5).^2 + y.^2));
figure
scatter3(x, y, z, 25, z, 'filled')
colormap(turbo)
colorbar
view(45,30)
x = randn(1, 1000);
y = randn(1, 1000);
z = exp(-(x.^2 + y.^2));
figure
scatter3(x, y, z, 25, z, 'filled')
colormap(turbo)
colorbar
.

댓글 수: 5

Francesco
Francesco 2024년 8월 5일
이동: Star Strider 2024년 8월 5일
YES!!!
I did it, thanks!
figure(1)
scatter(L01(:,2),L01(:,3),[],L01(:,10)/10^6,'+')
colorbar
xlim([-20 20])
ylim([-20 20])
xlabel('x [mm]')
ylabel('y-[mm]')
title('Gaf n. 1')
Francesco
Francesco 2024년 8월 5일
이동: Star Strider 2024년 8월 5일
is it correct like this?
As always, my pleasure!
Yes! That is correct. The syntax depends on the plot you want. For a 2D scatter plot, the fourth argument defines the colour of the markers.
Francesco
Francesco 2024년 8월 5일
Thanks a lot Star Strider,
If what I wrote is ok than your example helped my memory a lot!
Cheers
As always, my pleasure!
Thank you!

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

추가 답변 (1개)

Rahul Chowdhury
Rahul Chowdhury 2024년 8월 5일

0 개 추천

Try something like
M = [col1; col2; col10];
contourf(M, col10)
colorbar('Ticks', col10)
This creates a contour plot with the specific levels from col10 and while labeling them in a color bar. Let me know if this helps.

카테고리

도움말 센터File Exchange에서 Graphics Objects에 대해 자세히 알아보기

제품

릴리스

R2018a

태그

질문:

2024년 8월 5일

댓글:

2024년 8월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by