I tried to interpolate DATA (of size NixMi) from irregular polar grid (Xi and Yi of size NixMi) to regular grid (Xr and Yr of size NrxMr).
I tried with interpn(Xi,Yi,DATA,Xr,Yr)
But it didn't work and I received the error message : "Error using griddedInterpolant - Data is not valid NDGRID format".
I think this is because my entry grid has to be strictly monotonic.
I tried with scatteredInterpolant, griddata and griddatan but still a failure.
Do you have any ideas ?
Related
I am trying to interpolate data between points as shown in this
image. When I use the griddata function matlab, the interpolated data exceeds the boundary of the original data. The area of desired interpolation is highlighted by the boundary made in the figure. Is there any way around to this problem?
My code for interpolation an display
figure2 = figure;
[x , y] = meshgrid(min(Matrixmin(:,5)):0.01:max(Matrixmin(:,5)),min(Matrixmin(:,6)):0.01:max(Matrixmin(:,6)));%graduation des x et y.
[xi,yi,zi]=griddata(Matrixmin(:,5),Matrixmin(:,6),Matrixmin(:,10),x,y);
contourf(xi,yi,zi,'edgecolor','none','LevelStep',0.01);
h=colorbar('location','Eastout');colormap('jet');
I have also tried the interp2 function but the results are still the same.
You are creating query points [x, y] using meshgrid that are outside the boundary of your image. Then, griddata is estimating the zi values at those query points. Behavior of both meshgrid and griddata is as expected. If you do not want points outside the boundary of the image, use the inpolygon function to remove those points after creatingmeshgrid.
I have this data with values on the edges of the matrix and other values at evenly spaced interval within the matrix. I want to predict the values of the zero positions from the original values and make a heat map of the new data. Through suggest, I use scatteredInterpolant, ndgrid and interpolant since the data is that interp2 (matlab functions) cannot be used to interpolate the zero elements. Now, this method doe not give me a smooth figure and I am want to know if someone can offer some help. I have attached the figure from my code, the data and the code to this post.Thank you.
[knownrows, knowncolumns, knownvalues] = find(DataGrid); %get location and value of all non-zero points
interpolant = scatteredInterpolant(knownrows, knowncolumns, knownvalues,'linear'); %create interpolant from known values
[queryrows, querycolumns] = ndgrid(1:1:size(DataGrid, 1), 1:1:size(DataGrid, 2)); %create grid of query points
interpolatedj = interpolant(queryrows, querycolumns);
HeatMap(interpolatedj)
https://www.mediafire.com/?pq40x1ljxk8h996
https://www.mediafire.com/?pq40x1ljxk8h996
To plot a smoothed matrix you can use pcolor and set the shading parameter to interp
pcolor(M); %where M is your 2D matrix
shading interp %set the shading to interp
Try
image(M) or imagesc(M) where M is a matrix. pcolor(M) also works. If your matrix is huge then you need to remove edges otherwise figure just looks like blank image.
I'm testing out an algorithm and saved a dataset with 100x20 values that I successfully import as a matrix in Matlab and plot it using the surface command. That plot looks like.
Then I do the exact same thing but for a data set with 10 times the values on the y-axis (a 1000x20 matrix). This results in following picture, where the black rectangle are z-values seemingly at 0 rendered:
It's the exact same test so the same values should still exist, for the 0-100 part of the y-axis. The values look like they were imported correctly in the table before plotting but why does the surface plot look completely wrong?
There not much code... All i type is
x=data(1, 2:end)
y=data(2:end, 1)
test=data(2:end, 2:end)
and surface(x,y, test)
where test is the imported matrix using drag and drop to matlab and x, y are just simple vectors with correct dimensions since surface complains otherwhise.
looking through the table, there are no irregularities and using max and min shows nothing strange either:
I need to plot a 3D figure with each data point colored with the value of a 4th variable using a colormap. Lets say I have 4 variables X,Y,Z and W where W = f(X,Y,Z). I want a 3D plot with X, Y, and Z as the three axis. The statement scatter3(X,Y,Z,'filled','b') gives me a scatter plot in 3D but I want to incorporate the value of Z in the graph by representing the points as an extra parameter (either with different areas :bigger circles for data points with high value of Z and small circles for data points with low value of Z or by plotting the data points with different colors using a colormap). However, I am a novice in MATLAB and dont really know how to proceed. Any help will be highly appreciated.
Thanks in advance!
So just use z for the size vector (4th input) as well as the color vector (5th input):
z = 10*(1:pi/50:10*pi);
y = z.*sin(z/10);
x = z.*cos(z/10);
figure(1)
scatter3(x,y,z,z,z)
view(45,10)
colorbar
The size vector needs to be greater 0, so you may need to adjust your z accordingly.
You are already nearly there... simply use
scatter3(X,Y,Z,s,W);
where s is the point size (scalar, e.g. 3) and W is a vector with your W values.
You might also want to issue an
set(gcf, 'Renderer','OpenGL');
where gcf gets your current figure you are plotting in to significantly increase responsiveness when scattering a lot of data.
I have computed the gradients from every pixel location of a grayscale image, both on X and Y axis and this can result in a vector representation for each pixel location. I want to obtain a plot figure similar to the one illustrated bellow:
My image has 1000 x 1002 dimensions and I have computed the gradients for each pixel on X and Y directions so I have 2 matrices, each one having 1000 x 1002 dimensions.
I am interested in obtaining a plot similar to the one illustrated in the image above, where I show basically the direction of each vector obtained from the computed gradients. I do not care about the magnitude of the vector, so basically each arrow can have the same length.
Do you know how can I obtain something similar to this?
It works in my case:
[DX,DY] = imgradient(imageIn);
%show gradient
figure;
[x,y]=meshgrid(1:1:500);
figure
quiver(x,y,DX,DY)
hold off