# A question about two-dimensional random field

**URL:** <https://uqworld.org/t/a-question-about-two-dimensional-random-field/1854>\
**Category:** Community Q&A and How To\
**Created:** [April 7, 2023, 3:34am UTC](https://uqworld.org/t/a-question-about-two-dimensional-random-field/1854 "2023-04-07T03:34:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zehua309](https://uqworld.org/letter_avatar_proxy/v4/letter/z/e9a140/32.png) [@zehua309](https://uqworld.org/u/zehua309)\
**Post date:** [April 7, 2023, 3:34am UTC](https://uqworld.org/t/a-question-about-two-dimensional-random-field/1854/1 "2023-04-07T03:34:03Z")

</div>

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.

```matlab
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!

---

<div class="post-metadata">

**Author:** ![styfen.schaer](https://uqworld.org/user_avatar/uqworld.org/styfen.schaer/32/849_2.png) [@styfen.schaer](https://uqworld.org/u/styfen.schaer)\
**Post date:** [April 12, 2023, 12:51pm UTC](https://uqworld.org/t/a-question-about-two-dimensional-random-field/1854/2 "2023-04-12T12:51:22Z")

</div>

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:

```matlab
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
