I'm plotting a surface in matlab, where the x and y values are 0.15-0.85, with 0.05 gaps (0.15,0.2,0.25...).
However, when I plot the surface, the axis are on a 0.0 - 1.0 range, with 0.1 jumps (0.0, 0.1, 0.2...) so the entire surface is distorted. How do I set the axis ranges and deltas?
So as written in my comments you could solve your problem like this:
figure(1)
surf(data)
axis([0.15 0.85 0.15 0.85])
set(gca, 'XTick',0.20:0.05:0.80)
set(gca, 'YTick',0.20:0.05:0.80)
Related
I have some data fitted to an exponential function (y1) using the curve fitting app to calculate the coefficients. I then imported the model and the prediction intervals (p11; a 1441x2 matrix). (t and Asiii are imported datasets, just generated some data to explain the code)
S=[0.95,0.87,0.83,0.73,0.62,0.51,0.41,0.31,0.22,0.04,0.002,0,0,0,0];
t=[1,3,5,10,20,30,40,50,60,90,120,180,240,360,1440];
hold on
s2=scatter(t,Asiii,250,[0.1216, 0.8, 0.0157],'^','filled');
x = 0:1440;
y1 = 1.016*exp(-0.02349*x)
p1=plot(x,y1,'Color',[0.1216, 0.8, 0.0157],...
'LineWidth',1.5);
p11 = predint(model,x,0.95,'observation','on');
plot(x,p11,'--','Color',[0.4235, 0.9608, .6],...
'LineWidth',1.5);
%Patch
patch([x;x],[p11(:,1)';p11(:,2)'],'g');
%Fill
fill(x, p11,p11,'facecolor', 'red', 'edgecolor', 'none', 'facealpha', 0.4);
I want to have the area between the prediciton bounds/confidence intervals filled with a different color, but it seems I can only get a solid black shading using 'patch'.
I also tried using the 'fill' function but the polygons go all the way to the top of y-axis. Is there a way to adjust the Edge thickness/color?
I've imported a STL file in Matlab with the function stlread.
My question is, how can we rescale it with an arbitrary size factor (for instance, suppose you want to halve its dimensions)?
Here there is my piece of code in which the stl is imported and viewed:
fv = stlread ( 'Femur_Head.stl' );
patch(fv,'FaceColor', [0.8 0.8 1.0], ...
'EdgeColor', 'none', ...
'FaceLighting', 'gouraud', ...
'AmbientStrength', 0.15);
% Add a camera light, and tone down the specular highlighting
camlight('headlight');
material('dull');
axis([-50 50 -50 50 0 80]);
view([-135 35]);
title('Femur Head');
xlabel('X');ylabel('Y');zlabel('Z');
% Fix the axes scaling, and set a nice view angle
axis('image');
view([-135 35]);
hold on
View:
i have some datas which are included some deflection and force values. Like deltaX deltaY and forces measured at that points as Fx and Fy. I want to create a colormap at that points with the magnitude of forces and color transition between points in 2D. For example if point1 is red(high value, big deflection) and point2 is blue(low value, small deflection) i want color transition between them. Do you have any suggestion for that?
Data are given below.
First column positionX
second column positionY
third column forceX
forth column forceY
I need to plot this map according to X and Y positions and force magnitudes.
***When i take the magnitude of vectors we have positionX positionY and only 1 force value.
filein =
0 0 -0.0395 0.1189
0 1.5053 0.2127 -11.3568
-0.0008 3.0082 0.6719 -22.0470
-0.0048 4.5093 0.9231 -32.7004
0.0069 6.0033 1.2499 -43.2750
-0.0029 7.5008 1.6960 -53.4941
1.4981 0.0102 -1.5213 1.2031
1.4979 1.5003 -1.2326 -10.0738
1.5071 3.0043 -0.6965 -20.7386
1.4896 4.4943 -0.2563 -31.5026
1.5020 5.9921 0.0480 -42.3186
1.5021 7.4909 0.7614 -52.7354
3.0016 0.0022 -2.6099 1.9455
3.0022 1.4960 -2.6157 -9.3388
2.9959 3.0087 -1.8898 -20.1823
2.9955 4.4977 -1.3670 -30.7842
2.9923 6.0041 -0.8444 -41.7370
2.9976 7.5055 -0.2241 -52.1361
4.4995 -0.0016 -4.0576 2.5489
4.5009 1.4961 -3.8135 -8.6871
4.4930 2.9939 -3.0315 -19.4825
4.4986 4.5045 -2.6034 -30.2974
4.5046 5.9931 -1.9570 -40.9145
4.4972 7.5023 -1.1994 -51.4071
5.9931 -0.0014 -5.1986 3.2395
5.9954 1.5000 -5.1224 -7.9289
6.0017 2.9977 -4.3153 -18.7471
6.0045 4.4939 -3.6613 -29.4662
6.0030 6.0081 -2.9086 -40.3400
6.0003 7.5006 -2.1704 -50.6973
7.4974 -0.0018 -6.5690 4.0048
7.4977 1.5043 -6.5230 -7.0994
7.5047 3.0058 -5.5833 -18.0435
7.5083 4.5058 -4.8070 -28.6861
7.5024 6.0059 -4.0150 -39.4321
7.5006 7.5023 -3.1837 -49.8617
You can use meshgrid and surf or mesh command to plot it:
[X,Y] = meshgrid(filein(:,1),filein(:,2));
M = sqrt(filein(:,3).^2+filein(:,4).^2);
Z=meshgrid(M,M);
C = gradient(Z);
figure
surf(X,Y,Z,C);colorbar
You can remove the mesh and interpolate as follows:
surf(X, Y, Z,'EdgeColor', 'None', 'facecolor', 'interp');
Then view it from above:
view(2)
Imagine a dome with its centre in the +z direction. What I want to do is to move that dome's centre to a different axis (e.g. 20 degrees x axis, 20 degrees y axis, 20 degrees z axis). How can I do that ? Any hint/tip helps.
Add more info:
I've been dabbling with rotation matrices in wiki for a while. The problem is, it is not a commutative operation. RxRyRz is not same as RzRyRx. So based on the way I multiple it I get a different final results. For example, I want my final projection to have 20 degrees from the original X axis, 20 degrees from original Y axis and 20 degrees from original Z axis. Based on the matrix, giving alpha, beta, gamma values 20 (or its corresponding radian) does NOT result the intended rotation. Am I missing something? Is there a matrix that I can just put the intended angles and get it at the end ?
Using a rotation matrix is an easy way to rotate a collection of (x,y,z) points. You can calculate a rotation matrix for your case using the equations in the general rotation section. Note that figuring out the angle values to plug into those equations can be tricky. Think of it as rotating about one axis at a time and remember that the order of your rotations (order of multiplications) does matter.
An alternative to the general rotation equations is to calculate a rotation matrix from axis and angle. It may be easier for you to define correct parameters with this method.
Update: After perusing Wikipedia, I found a simple way to calculate rotation axis and angle between two vectors. Just fill in your starting and ending vectors for a and b here:
a = [0.0 0.0 1.0];
b = [0.5 0.5 0.0];
vectorMag = #(x) sqrt(sum(x.^2));
rotAngle = acos(dot(a,b) / (vectorMag(a) * vectorMag(b)))
rotAxis = cross(a,b)
rotAxis =
-0.5 0.5 0
rotAngle =
1.5708
I have a distribution of tube radius r, and I would like to plot tubes for all the sampled r in single figure as shown in the figure above. The tubes have following characteristics:
The length of all tubes is constant, but radius is varying.
The narrowest tube will be completely filled
with light gray color.
The length of the light gray color from bottom in all other tubes is
inversely proportional to the radius of the tube i.e.
length of light grey color from bottom = constant/r
The remaining length of the tube will be filled with dark gray color.
Magnitudes of r and total length of each tube is of the order of 1e-005m and 1e-002 m, respectively, so they need to be standardized compared to the X and Y axes units.
The white interspaces are just spaces and not tubes.
UPDATE (Based on the answer by Boris)
This is the code from Boris in which I made certain changes based on the characteristics of the tubes that I have described above. I am having scaling issues as I am not able to visualize my network of tubes as clearly as can be seen in the figure above.
function drawGrayTube (x, r, sigma_wn, theta, del_rho, rmin, rmax,L)
% sigma_wn is in N/m (=Kg/s^2), theta is in degrees, del_rho is in Kg/m^3
% and L is in m
h=((2*sigma_wn*cos((pi/180)*theta))./(del_rho*9.81.*r));
hmin=((2*sigma_wn*cos((pi/180)*theta))./(del_rho*9.81.*rmax));
hmax=((2*sigma_wn*cos((pi/180)*theta))./(del_rho*9.81.*rmin));
rectangle ('Position',[x,0,r/rmax,h], 'FaceColor',[0.7,0.7,0.7]);
ylim([0 1]);
if L>h
rectangle ('Position',[x,L,r/rmax,L-h], 'FaceColor',[0.3,0.3,0.3]);
ylim([0 1]);
else
rectangle ('Position',[x,L,r/rmax,L], 'FaceColor',[0.3,0.3,0.3]);
ylim([0 1]);
end
end
A simple function to draw the gray tubes could be for instance
function drawGrayTube (x, w, h)
rectangle ('Position',[x,0,w,h], 'FaceColor',[0.7,0.7,0.7]);
rectangle ('Position',[x,h,w,100-h], 'FaceColor',[0.3,0.3,0.3]);
end
Hereby, x is the x position of the tube, w denotes the width and h between 0 and 100 the height of the light gray part of the tube.
You can now use it in your example by calling
drawGrayTube (x, r, 100*constant/r)
where you have to adapt the constant such that constant/r is at most 1.
You can write a similar function for the white interspaces.
Assume that you have given a vector of radii (already scaled such that the values are between 0 and 1), e.g., r=[0.5, 0.7, 0.9, 0.1, 0.5, 0.01] then on possibility to draw the tubes is
interspace = 0.5;
for i=1:length(r)
drawGrayTube(sum(r(1:i-1))+i*interspace, 100*r(i)+1e-10, r(i)+1e-10);
end
You should use the function rectangle