A question about two-dimensional random field

Hi everyone,
Recently I am studying the random field module in uqlab, and I have a question about the example of ‘Multi-dimensional random fields’.
In this case, the realization figure of a two-dimensional random field can be drawn by the code of ‘uq_display(myRFInput);’, but I can get the data of this two-dimensional random field.
The code, ‘X = uq_getSample(300);’, can only get 300 random one-dimensional matrix instead of the two-dimensional matrix corresponding to the previously made figure.
In my opinion,the coordinates of these 1D matrices are the same as those in the covermesh.So I used the following code to get the data from the random field.

clc;clear
rng(100,'twister')
uqlab
RFInput.Type = 'RandomField' ;
RFInput.Corr.Family = 'Gaussian' ;
RFInput.Mean = 1 ;
RFInput.Std = 1 ;
RFInput.DiscScheme='KL';
RFInput.Corr.Length= [0.2, 0.6] ;
x = linspace(-1,1,50);
y= linspace(-1,1,50);
[X,Y] = meshgrid(x,y);
RFInput.Mesh= [X(:) Y(:)];
%%
aaa = uq_createInput(RFInput);
aaa.RF
X_1 = uq_getSample(300);
X_2=X_1(1,:);
A=zeros(50,50);
for i=1:50
   A(i,:)=X_2((1:50)+50*(i-1));
end
figure          
surf(X,Y,A)
shading interp
colorbar
view([90, 90]);     
title('surf + view');
uq_print(aaa);
uq_display(aaa);

Is this method correct, or is there a way to get the data directly in uqlab.Please favour me with your instructions.Thanks!

Dear @zehua309

What you are doing is correct. However, here is a different way to plot the 2D random field and I think that is what you asked for:

figure  
tri = delaunay(RFInput.Mesh(:,1), RFInput.Mesh(:,2));
trisurf(tri, RFInput.Mesh(:,1), RFInput.Mesh(:,2), X_1(1,:));
shading interp
colormap parula
view(0,270) % UQLab does view(0,90) but view(0,270) gives a plot identical to yours

Best regards
Styfen

1 Like