在MATLAB中沿z轴创建堆叠的2d矩阵

时间:2017-09-24 21:46:13

标签: matlab graphics matlab-figure

下图只是一个带冲浪的二维数组的表示。我想创建一个类似的图形,其中10个这样的2d阵列堆叠在一起,沿着z轴有一些偏移。

figure();
surf(X);
colormap(hsv);
shading interp;
campos([-70 -150 80]);
grid on;
set(gcf,'color','w');

enter image description here

1 个答案:

答案 0 :(得分:3)

只需使用package sample; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.TextField; import javafx.stage.Stage; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.VBox; public class Main extends Application { @Override public void start(Stage primaryStage) throws Exception{ Image imgUsa = new Image ("http://gifimage.net/wp-content/uploads/2017/06/american-flag-gif-13.gif"); Image imgChina = new Image ("http://bestanimations.com/Flags/Asia/china/chinese-flag-waving-gif-animation-10.gif"); ImageView ivUsa = new ImageView(imgUsa); ImageView ivChina = new ImageView(imgChina); TextField errorText = new TextField(); if (imgChina.isError()) { errorText.setText(imgChina.getException().getMessage()); } VBox root = new VBox(ivUsa, ivChina, errorText); Scene scene = new Scene(root, 1000, 500); primaryStage.setTitle("Flags"); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { Application.launch(args); } } 多次调用surf,然后应用逐渐增加的偏移量。

通过默认hold on的1输入版本),偏移将影响每个曲面显示的颜色。这是一个有三个2D阵列的例子。请注意,每个峰峰值幅度都不同。

surf

enter image description here

为了防止偏移影响颜色,即为所有表面实现一致的颜色,请使用2个或4个输入版本的x{1} = .2*peaks(30); x{2} = .4*peaks(30); x{3} = .8*peaks(30); % cell array containing three 2D arrays offset = 7; % desired offset hold on for k = 1:numel(x) surf(x{k} + offset*(k-1)) end campos([-100 -170 90]) grid on 分别指定高度和颜色:

surf

enter image description here

根据值生成带颜色的堆积平面(无高度变化):修改输入参数,如下所示:

x{1} = .2*peaks(30);
x{2} = .4*peaks(30);
x{3} = .8*peaks(30);
offset = 7;
hold on
for k = 1:numel(x)
    surf(x{k} + offset*(k-1), x{k}) % Only this line has been changed
end
campos([-100 -170 90])
grid on

enter image description here