I am having difficulty producing a contour plot from two matrices;
I have one matrix A 9×8 with values (an amount of something), and another matrix 9×8 B where each entry corresponds to a location of an entry in A.
The issue is that the entries do not fall on a rectangular grid.
I'm trying to create a contour plot of the Y-Axis values (from matrix A), based on the X-axis values from matrix B.
I've tried meshgrid (based on the x and y ranges for B), however the values in matrix B are not evenly spaced;
Any help would be greatly appreciated!
Related
For example, I got 3 pairs of 1-D loglog curves and additionally their associated cartesian coordinate points (x,y,z) of one of their ends A, B and C over a mesh surface S (z is positive downwards and linear but coincides in direction with the log(y)-axis from the curves). Is it possible to respresent in a single figure such system of plots in matlab?
Moreover, obtain an interpolated slice from A,B and C?
The images from the question of user3281667 gives an insight of what we are trying to do here:
https://gis.stackexchange.com/questions/252939/interpolating-xyz-data-in-arcgis-3d-analyst
Thanks.
Kind of solved. First we need to know in which format is our data, this case scattered.
I concatenated a nx4 matrix with the preprocessed data A=[X Y Z C].
Then use the right tools, to plot use scatter3: scatter3(A(:,1), A(:,2), A(:,3),30, A(:,4), 'filled' )
Now to interpolate, fisrt generate a grid refinement with meshgrid: [Xm, Ym, Zm] = meshgrid(min(X):2:max(X), min(Y):2:max(Y), min(Z):2:max(Z)) next interpolate using griddata Cm = griddata(X,Y,Z,C,Xm,Ym,Zm);and last plot again.
figure
scatter3(Xm(:), Ym(:), Zm(:), 30, Cm(:), 'filled' )
Thanks to user7431005
I have 2 matrices of numbers(images) with different sizes, which represent some measurement of a 2D object. Each row of the matrices represents a measurement widthwise of the object, at some distance from the source of the object. Each column represents a slice along the object.
I want to merge the two matrices into one matrix (image), so that the second matrix (B), which represents a measurement further from the source, will be below the first matrix (A).
The problem is that matrix A has different sampling than B:
A has 2541 columns, which correspond to the sampling vector: x1 = -6.375 : 0.005 : 6.325 (mm), and
B has 5101 columns, which correspond to the sampling vector: x2 = -25.55 : 0.01 : 25.45 (mm).
I thought to solve the problem by merging the sampling vectors and using interp1 in order to have the two matrices with the same number of columns:
x_merged=sort([x1 x2]);
interped_A=interp1(x1, A' , x_merged , 'spline','extrap')';
interped_B=interp1(x2, B' , x_merged , 'spline','extrap')';
y_mm=0.23:0.1:(0.23+0.1*(size(A,1)-1));
figure; imagesc(x1,y_mm,A); colorbar
figure; imagesc(x_merged,y_mm,interped_A); colorbar
However, I encountered a problem doing so:
The resulting image of interped_A (for example), does not have the same value at a certain (x,y) point, as the value of A !!
It is demonstrated below:
The first figure is of A, and it has at the indicated point (for example), a value two orders of magnitude lower than the indicated value of the same point at the second figure, which is of interped_A.
What is the problem and how can I fix it ? ?
(Please help me!!)
i am having 3D matrix in which most of the values are zeros but there are some nonzeros values.
when I am plotting this 3D matrix in matlab I am getting plot like as below
here u can see there are two groups of points are nearer to each other(that's why the color became dark) and two individual group of points is far away....
so my objective is to cluster that two nearer group of points and make it as one cluster1 and other two will be called as cluster2 and cluster3 ....
I tried kmeans clustering, BIC clustering...but as kmeans clustering is basically build up for 2D data input, I faced hurdle there ...then I reshape 3D matrix into 2D matrix but still I am getting another error Subscripted assignment dimension mismatch
so could u plz come out with some fruitful idea to do this......
Based on your comment that you used vol3d I assume that your data has to interpreted this way. If your data-matrix is called M, try
[A,B,C] = ind2sub(size(M),find(M));
points = [A,B,C];
idx = kmeans(points,3);
Here, I assumed that M(i,j,k) = 1 means that you have measured a point with properties i,j and k, which in your case would be velocity, angle and range.
I have a data matrix contains 18 samples, each with 12 variables, D(18,12). I performed k-means clustering on the data to get 3 clusters. I want to visualize this data in 2 dimensions, specifically, along the 2 eigenvectors corresponding to the largest eigenvalues of a specific matrix, B. So, I create the plane spanned by two eigenvectors corresponding to the largest two eigenvalues:
[V,EA]=eig(B);
e1=V(:,11);
e2=V(:,12);
for i=1:12
E(i,1)=e1(i);
E(i,2)=e2(i);
end
Eproj=E*E';
where e1 and e2 are the eigenvectors, and E is a matrix containing those column vectors. At this point, I'm kind of stuck.
I recognize that e1 and e2 are orthogonal in this 12-d space, but I have no idea how this can reduce to two dimensions so I can plot it.
I believe that the projection of a data sample onto the plane would be:
Eproj*D(i,:)
for i=1...18, but I'm not sure where to go from here to plot my clusters. When I do the projection, its still in 12 dimensions.
Principal Component Analysis can help you to transform the data into 2D using the Eigenvectors.
coeff = princomp(B);
Bproj = B * coeff(:,1:2);
figure
plot(Bproj(:,1),Bproj(:,2),'*')
If you have the labels you can use the "scatter" function for a better visual. Or you can reduce the dimensionality to 3 and use "scatter3" function.
I have multiple vectors of varying lengths that I would like to plot next to each other in 3D space in Matlab.
As an example:
Say I have three vectors:
X is a 5x2 vector,
Y is a 10x2 vector and
Z is a 15x2 vector.
Each element of every vector has the format:
x value, y value
but the x values of the various vectors do not match.
I would like to plot these vectors in 3D space, next to each other. The reason why I don't want to plot them using "hold" is because most of the data have the same values, but I would like to see how many of the plots have the same value at a specific time.
I hope my questions makes sense. Please just ask if anyone is unsure.
I think you are looking for the function ribbon.
Documentation: http://www.mathworks.fr/help/techdoc/ref/ribbon.html
EDIT:
if your x's do not have the same length, you can combine it with interp1 as follow:
x1=0:0.1:1;
x2=0:0.02:1.5;
y1=x1.^2;
y2=sqrt(x2);
y2=interp1(x2,y2,x1);
ribbon(x1',[y1;y2]')