Save the values of Surface function in MATLAB - matlab

I use the surf function in MATLAB in order to create a 3D map.
This map is created by 2 vectors and for each combination of their values I have a third one that creates the surface.
Is there a way to save for each iteration these sets of three values somehow?
What I want to achieve is to have a matrix which will be as a map for every possible combination of these values.
I've made some efforts with 3D matrices but I made it even more complex and I had many errors because of the dimensions.

Related

How to perform a t-test on a 3D array?

I have a series of 3D arrays of dimensions 3x3x3 in Matlab. Matlab's ttest function returned 2D arrays and when I checked out the documentation I see that the method performs t-tests on columns. I want to perform a t-test that goes over the entire matrix space. How can I code this without manually creating my own t-test script?
Edit: I am hoping to get two outputs that contain the p-values and t-values output by the ttest method like in
[~,pval,~,tval] = ttest(x,y)
but thise only gives the 2D arrays mentioned above. I require the output be a 3x3x3 array giving the t-value at each point, and ideally another that contains the p-value corresponding to those t-values.

Regridding data from 2D grid to another

i'm working on a project involving netcdf data analisys. To correctly process the data i need to regrid it to a coarser level. The matrix is in fact multidimensional, but i only need spatial regridding, so basically i have to work with a lat/lon matrix.
The process i had in mind would consist, giving a source 2d grid (the one retrived from the netcdf) and a destination grid ( the one that i need for my calculations) the second of wich is coarser(have less points),in calculating a sort of weight matrix that contains the coefficients needed to compute each point of destination grid.
This will be helpful because i have a bunch of variables laying on the same grid, so if i calculate a weight matrix, the problem is reduced in a sequence of matrices multiplications.
basically what i need is a function f(lat_source,lon_source,lat_dest, lot_dest) that given the coords of the source/destinaiton grids return a matrix of weights that maps the dest lat/lon onto the source one.
is there something already implemented ? Or some reads that could point me in the right direction ?
I know there are different interpolation methods that could be used, but, for the sake of the argument, let's suppose a linear interpolation.

Interpolating 3D points from input points corresponding to a closed surface

I have a list of scattered 3D points similar to the one below:
Using MATLAB, I want to interpolate further points from the surface that those original points correspond to, in order to obtain a more complete scatter. Note that there are no particular slices defined on this scattered data. That is, the z values of the point cloud are not discrete, so it's not possible to interpolate slice by slice.
I think that the ideal way to achieve this would be to somehow obtain the smooth closed surface which best matches the scattered data, and then sample it. But I have found no straightforward way to achieve this.
The scatterinterpolant class could be a simple option.
Use scatteredInterpolant to perform interpolation on a 2-D or 3-D
Scattered Data set. For example, you can pass a set of (x,y) points
and values, v, to scatteredInterpolant, and it returns a surface of
the form v = F(x, y). This surface always passes through the sample
values at the point locations. You can evaluate this surface at any
query point, (xq,yq), to produce an interpolated value, vq.
http://au.mathworks.com/help/matlab/math/interpolating-scattered-data.html
Scattered data consists of a set of points X and corresponding values
V, where the points have no structure or order between their relative
locations. There are various approaches to interpolating scattered
data. One widely used approach uses a Delaunay triangulation of the
points.

Using Matlab's histogram() to simultaneously plot two sets of data

I have an matrix A containing two columns for two sets of data. I want to plot these on the same histogram, using different colors for the bars representing the class intervals. I can do this using hist(A), in which case each column in the matrix is taken as a distinct set of data. I would like to use histogram() instead, and also define edges for bins. How can I do this?
The answer is simpler than I thought:
histogram(A(:,1))
hold on
histogram(A(:,2))
This automatically makes the bars transparent, so both can be seen.

MATLAB: plotting multiple columns of a matrix

Inside a MATLAB function I have built a matrix A, whose dimensions M and N are set as parameters of the function. I would like to plot all the columns of this matrix, given a vector of indices B with length M. Hence, I use these lines:
figure
plot(B,A)
I specified figure as the MATLAB function returns more different plots.
My problem is that the program plots just two columns of the matrix with different colours (blue and violet). Where is my mistake?
Thank you for your attention.
go for
plot(repmat(B,1,N),A);
or
plot(repmat(B,N,1),A);
(depending on your rows/columns). You need to have same size matrices in plot.
Moreover, if B are just consecutive indexes, you may want to consider Plot(A) (or Plot(A')).
I noticed that there was an error which caused the overlap of the different curves, so the way which I used to plot the colums of a matrix is valid. However, the method proposed by Acorbe is a possibility, too.