I am trying to plot the diagram (not exactly the same but which appears to be 3D) as attached here. I have various vectors available, whose size are as follows: alpha = 1x11 , beta = 1x11 and BER = 11x11.enter image description here
I tried using surf, meshgrid commands in MATLAB but not getting it properly.
Any help in this regard will be highly appreciated.
Related
How do I apply a vector field obtained via quiver, to an image which causes the pixels to displace in the direction of the vectors (image is warped)?
Also, if the vector field I have is 3 dimensional, how would I do this? Think of it as laying down a flat 2 dimensional image over a 3 dimensional terrain. How would I go about viewing this in matlab?
Thank you for your time
EDIT: I have to warp the image not just in the Z axis, but along the X and Y axes as well.
Laying down a flat 2 dimensional image over a 3 dimensional terrain:
It's not very clear the way the axes are oriented but this is an image of a clown mapped on the peaks function. Exact steps are described in the documentation of surface in the example 'Display image along surface plot.'
load clown
C = flipud(X);
figure
surface(XD,YD,ZD,C,...
'FaceColor','texturemap',...
'EdgeColor','none',...
'CDataMapping','direct')
colormap(map)
view(-35,45)
Essentially, you create your surface with CData as the image you want to be displayed and set an appropriate colormap for the axes.
Use the imwarp function in the Image Processing Toolbox.
I have a 3D matrix of a MRI image and used matlab edge function and it gave me a 3D matrix as follow which some of the points are 1 (means edges).
I want to show this surface in matlab but I don't know that how I should do this. I know that I should use surf.
As #bdecaf said, you can use find to determine the height of the points, or in other words, in which of the 100 layers does the point lie. You can do that as follows:
z1=zeros(30,100);
temp=find(b);
[row,col,layer]=ind2sub(size(b),temp);
for i=1:size(x,1)
z1(row(i),col(i))=layer(i);
end
You can get an image as follows:
I am in the process of comparing various contourplots from Ansys Fluent and Matlab. Everything is plotted on the same coordinates and with the same caxis limits. However I am struggling to get the colormaps to match. Exporting the data from fluent to matlab is not an option unfortunately.
I have the Ansys Fluent colormap saved as a .jpg or .png. I am trying to make a custom colormap for matlab from [url=http://www.arc.vt.edu/ansys_help/flu_ug/graphics/g_flu_ug_panel_cmap.png image similar to this[/url] so I can plot my matlab data with the same colormap. Obviously I clipped away the uneccesary data so that just the colormap was left.
I have tried to do something with imread and rgb2ind but that gave me some very funky results.
h=imread('custom_colormap.jpg')
[X, map] = rgb2ind(h,50);
colormap(map);
Your ideas are much appreciated.
Have you tried just creating your own custom colormap? You can do it quite easily using the colormapeditor tool:
Do you need that exact map? You can get pretty close by trimming Matlab's hsv map:
n = 20; %// desired number of colors
t = .7; %// trimming factor
cm = hsv(ceil(n/t));
cm = cm(1:n,:);
%// cm = flipud(cm); %// if needed. Thanks to Dan
colormap(cm);
colorbar
I am trying to plot a 3d view of a very large CT dataset. My data is in a 3d matrix of 2000x2000x1000 dimension. The object is surrounded by air, which is set to NaN in my matrix.
I would like to be able to see the greyscale value of the surface of the object (no isosurface) but I cannot quite work out how to do that in Matlab. Can anyone help me please?
Given that I a dealing with a huge matrix and I am only interested in the surface of the object, does anyone know a good trick how to reduce the size of my dataset?
The function surf(X,Y,Z) allows you to plot 3d data, where (X,Y) gives the coordinates in the x-y-plane while Z gives the z-coordinate and the surface color.
By default the function does not plot anything for the NaN entries, so you should be good to go with the surf function.
To set the surf-function to use a grayscale plotting use:
surf(matrix3d);
colormap(gray);
This plots the matrix in a surface plot and sets the colormap to grayscale.
In addition, as I understand your data, you might be able to eliminate entire plane-segments in your matrix. If for instance the plane A(1,1:2000,1:1000) is NaN in all entries you could eliminate all those entries (thus the entire Y,Z-plane in entry X=1). This will however require some heavy for loops, which might be over the top. This depends on how many data matrices you have compared to how many different plot you want for each matrix.
I will try to give you some ideas. I assume lack of a direct 3D "surface detector".
Since you have a 3D matrix where XY-planes are CT scan slices and each slice is an image, I would try to find edges of each slice say with edge. This would require some preprocessing like first thresholding each slice image. Then I can either use scatter3 to display the edge data as a 3D point cloud or delaunay3 to display the edge data as a surface.
I hope this will help you achieve what you are asking for.
I managed to get it working:
function [X,Y,Z,C] = extract_surface(file_name,slice_number,voxel_size)
LT = imread(file_name);%..READ THE 2D MAP
BW = im2bw(LT,1);%..THRESHOLD TO BINARY
B = bwboundaries(BW,8,'noholes');%..FIND THE OUTLINE OF THE IMAGE
X = B{1}(:,1);%..EXTRACT X AND Y COORDINATES
Y = B{1}(:,2);
indices = sub2ind(size(LT),X,Y);%..FIND THE CORRESPONDING LINEAR INDICES
C = LT(indices);%..NOW READ THE VALUES AT THE OUTLINE POSITION
Z = ones(size(X))*slice_number;
I can then plot this with
figure
scatter3(X,Y,Z,2,C)
Now the only thing I could improve is to have all these points in the scatter plot connected with a surface. #upperBound you suggested delaunay3 for this purpose - I cannot quite figure out how to do this. Do you have a tip?
I've been googling for a while but couldn't find a solution for my problem. I am an amateur matlab user and I would like to create a 3D scatterplot, for this I have a matrix containing several points in 3D space:
>> size(A)
ans =
2511 3
I was able to create a 3D scatterplot using "scatter3" function, but now I am stuck a bit at color-coding the 3D points.
scatter3(A(:,1),A(:,2),A(:,3));
This will plot the data, but now I would like to add a color coding based on the z-Value...
The colors themself don't matter too much. It could be a rainbow spectrum or a temperature spectrum or whatever. I just would like to colorcode them to distinguish the z-Values of the points.
Can anybody help me with this? Thank you!
You have to give some more arguments to scatter3.
scatter3(X,Y,Z,S,C);
S lets you specify areas for each markers (with a vector) or a single area for all the markers, while C lets you specify color. If C is a vector, its values will be linearly mapped to the current colormap. To change the colormap, call colormap(jet) for example. See the documentation on colormap.
Sorry if that's confusing. Short version:
scatter3(A(:,1),A(:,2),A(:,3),9,A(:,3));
colormap(jet); %# or other colormap