根据 z 值将颜色设置为 z 值
Set color to z-values based on the z-values
我有一个要着色的表面。 z 值取自范围为 -10 到 2 的 100x100 矩阵,我想要符合
的内容
If z is between -10 and -9, color [1 0 0]
If z is between -9 and -8, color [.9 0 0]
....
If z is between -1 and 0, color [.1 0 0]
If z is between 0 and 1, color [0 0 .5]
If z is between 1 and 2, color [0 0 1]
现在,我想在不同的曲面图上使用完全相同的颜色图。同样,这些新的 z 值取自 100x100 矩阵,但其值的范围仅为 -5 到 1。所以,我想要
If z is between -5 and -4, color [.5 0 0]
If z is between -4 and -3, color [.4 0 0]
....
If z is between -1 and 0, color [.1 0 0]
If z is between 0 and 1, color [0 0 .5]
有没有什么方法可以实现这一点,而无需在每次我有一个要着色的新表面时手动定义一个新的颜色贴图?
由于我无法理解您的颜色图的底层模式(因此将其转换为一个 for 循环,该循环根据当前正在处理的数据范围自动计算当前颜色),我建议:
z_1 = randi([-10 2],100);
cmap_1 = cell(size(z_1));
cmap_1(z_1 < -9) = {[1.0 0.0 0.0]};
cmap_1(z_1 >= -9 & z_1 < -8) = {[0.9 0.0 0.0]};
% ...
cmap_1(z_1 >= -1 & z_1 < 0) = {[0.1 0.0 0.0]};
cmap_1(z_1 >= 0 & z_1 < 1) = {[0.0 0.0 0.5]};
cmap_1(z_1 >= 2) = {[0.0 0.0 1.0]};
z_2 = randi([-5 1],100);
cmap_2 = cell(size(z_2));
cmap_2(z_2 < -4) = {[0.5 0.0 0.0]};
cmap_2(z_2 >= -4 & z_2 < -3) = {[0.4 0.0 0.0]};
% ...
cmap_2(z_2 >= -1 & z_2 < 0) = {[0.1 0.0 0.0]};
cmap_2(z_2 >= 0) = {[0.0 0.0 0.5]};
要检索值及其各自的颜色:
my_z = z_1(2,19);
my_col = cmap_1{2,10};
我有一个要着色的表面。 z 值取自范围为 -10 到 2 的 100x100 矩阵,我想要符合
的内容If z is between -10 and -9, color [1 0 0]
If z is between -9 and -8, color [.9 0 0]
....
If z is between -1 and 0, color [.1 0 0]
If z is between 0 and 1, color [0 0 .5]
If z is between 1 and 2, color [0 0 1]
现在,我想在不同的曲面图上使用完全相同的颜色图。同样,这些新的 z 值取自 100x100 矩阵,但其值的范围仅为 -5 到 1。所以,我想要
If z is between -5 and -4, color [.5 0 0]
If z is between -4 and -3, color [.4 0 0]
....
If z is between -1 and 0, color [.1 0 0]
If z is between 0 and 1, color [0 0 .5]
有没有什么方法可以实现这一点,而无需在每次我有一个要着色的新表面时手动定义一个新的颜色贴图?
由于我无法理解您的颜色图的底层模式(因此将其转换为一个 for 循环,该循环根据当前正在处理的数据范围自动计算当前颜色),我建议:
z_1 = randi([-10 2],100);
cmap_1 = cell(size(z_1));
cmap_1(z_1 < -9) = {[1.0 0.0 0.0]};
cmap_1(z_1 >= -9 & z_1 < -8) = {[0.9 0.0 0.0]};
% ...
cmap_1(z_1 >= -1 & z_1 < 0) = {[0.1 0.0 0.0]};
cmap_1(z_1 >= 0 & z_1 < 1) = {[0.0 0.0 0.5]};
cmap_1(z_1 >= 2) = {[0.0 0.0 1.0]};
z_2 = randi([-5 1],100);
cmap_2 = cell(size(z_2));
cmap_2(z_2 < -4) = {[0.5 0.0 0.0]};
cmap_2(z_2 >= -4 & z_2 < -3) = {[0.4 0.0 0.0]};
% ...
cmap_2(z_2 >= -1 & z_2 < 0) = {[0.1 0.0 0.0]};
cmap_2(z_2 >= 0) = {[0.0 0.0 0.5]};
要检索值及其各自的颜色:
my_z = z_1(2,19);
my_col = cmap_1{2,10};