필터 지우기
필터 지우기

How to make the colorbar/colormap with colors the same as ANSYS in Matlab?

조회 수: 7 (최근 30일)
In ANSYS, when there is zero deflection, the color is blue. For maximum negative and maximum positive, red is shown. In matlab, when there is zero deflection, the color is green. For maximum positive deflection the color is red and for maximum negative deflection the color is blue. How to configure Matlab to display the same colorbar as Ansys?
See the difference between the figures:
Matlab:
Ansys:
Thank you!

채택된 답변

William Rose
William Rose 2024년 5월 28일
편집: William Rose 2024년 5월 28일
[edit: Fix spelling errors in my remarks. No changes to the code.]
x=0:.01:6; y=0:.01:2;
[X,Y]=meshgrid(x,y);
Z=sin(pi*X/2).*sin(pi*Y/2);
% plot results
figure
surf(X,Y,Z,EdgeColor="none");
axis equal; grid on; colorbar
xlabel('X'); ylabel('Y'); zlabel('Z')
%make custom color map
hue=[0:.01:.67,.66:-.01:0]';
nc=length(hue);
colors=hsv2rgb([hue,ones(nc,2)]);
colormap(colors)
The key is to recognize that progression from red through green to blue corresponds to hue=0 (red), hue=0.333 (green), hue=0.667 (blue). Then you want to go backwards, from blue to green to red. Therefore you can create a hue vector which goes in steps from 0 to 0.67, then back to 0. Then convert the hue vector to RGB colors, since the colormap() function wants a set of RGB colors. When converting the hue vector to RGB colors with hsv2rgb(), use a column of ones for the saturations and a column of ones for the values (S and V in "HSV").
  댓글 수: 3
William Rose
William Rose 2024년 5월 29일
@Lidianne Mapa, you're welcome.
@Mario Malic, Ansys is plotting negative as well as positive deflections on the z-axis. But the label on the Ansys colorbar only shows the magnitude, or, equivalently, it only shows deflection values from 0 to 1. I don't know how to make Matlab do this.

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

추가 답변 (0개)

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by