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:
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 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)
I would like to know how to draw the following meshes in such color in Matlab. The images are extracted from Microsoft paper on Kinect (link). It seems there is no default colormap of these sort. Do I need to create a new colormap?
The image shown is from figure 1, where they write that the lighting is Phong-shaded renderings (greyscale). This is what you call "silver-colored", i.e. colormap('gray') combined with reflections.
A quick google search suggests you looking at https://se.mathworks.com/matlabcentral/fileexchange/35240-matlab-plot-gallery-change-lighting-to-phong/content/html/Lighting_Phong.html
I've tried to make a custom milky colormap.
trisurf(tri, vertex(:, 1), vertex(:, 2), vertex(:, 3), 0, 'edgecolor', 'none');
axis equal;
axis vis3d;
light('Position', [0 0 1], 'Style', 'infinite');
colormap jet;
map = [0.83,0.82,0.78
1,1,1];
colormap(map);
lighting phong;
The result goes like this,
I have two matrices
timeline = [0.0008 0.0012 0.0016 0.0020 0.0024 0.0028];
Origdata =
79.8400 69.9390 50.0410 55.5082 34.5200 37.4486 31.4237 27.3532 23.2860 19.3039
79.7600 69.8193 49.8822 55.3115 34.2800 37.1730 31.1044 26.9942 22.8876 18.9061
79.6800 69.6996 49.7233 55.1148 34.0400 36.8975 30.7850 26.6352 22.4891 18.5084
79.6000 69.5799 49.5645 54.9181 33.8000 36.6221 30.4657 26.2762 22.0907 18.1108
79.5200 69.4602 49.4057 54.7215 33.5600 36.3467 30.1464 25.9173 21.6924 17.7133
79.4400 69.3405 49.2469 54.5249 33.3200 36.0714 29.8271 25.5584 21.2941 17.3159
When I plot them, I get a graph like below.
plot(timeline, Origdata, '.');
How can I draw a circle of radius 0.3524 value around each point? This radius should be relative to the y-axis only.
You can do this easily using viscircles (which requires the Image Processing Toolbox) however I don't think that the output is actually what you're expecting.
radius = 0.3524;
dots = plot(timeline, Origdata, '.');
hold on
for k = 1:numel(dots)
plotdata = get(dots(k));
centers = [plotdata.XData(:), plotdata.YData(:)];
% Ensure the the colors match the original plot
color = get(dots(k), 'Color');
viscircles(centers, radius * ones(size(centers(:,1))), 'Color', color);
end
The reason that it looks like this is because your X data is very close together relative to your y data and for circles to appear as circles, I have forced the x and y scaling of the axes to be equal (axis equal)
Edit
If you only want the radius to be relative to the y axis (distance) then we actually need to draw ellipses with an x and y radius. We want to scale the "x-radius" to make it appear as a circle regardless of your true axes aspect ratio, something like this can actually do that.
The trick to the code below is setting the data and plot aspect ratios (pbaspect and daspect) to manual. This ensures that the aspect ratio of the axes doesn't change during zoom, resizing, etc and makes sure that our "circles" remain circular-looking.
dots = plot(timeline, Origdata, '.');
drawnow
% Force the aspect ratio to not change (keep the circles, as circles)
pbaspect('manual')
daspect('manual')
hold on
aspectRatio = daspect;
t = linspace(0, 2*pi, 100);
t(end+1) = NaN;
radius = 4.3524;
% Scale the radii for each axis
yradius = radius;
xradius = radius * aspectRatio(1)/aspectRatio(2);
% Create a circle "template" with a trailing NaN to disconnect consecutive circles
t = linspace(0, 2*pi, 100);
t(end+1) = NaN;
circle = [xradius*cos(t(:)), yradius*sin(t(:))];
for k = 1:numel(dots)
x = get(dots(k), 'XData');
y = get(dots(k), 'YData');
color = get(dots(k), 'Color');
% Center circle template at all points
circles = arrayfun(#(x,y)bsxfun(#plus, [x,y], circle), x, y, 'uni', 0);
circles = cat(1, circles{:});
plot(circles(:,1), circles(:,2), 'Color', color)
end
Just to demonstrate, if we increase the circle radius to 4.3524 we can see the circles better.
And this works with all resizing etc.
To draw circles in MATLAB, you obviously have to use the rectangle function ;)
As mentioned in my comment, the size of 0.3524 does not match your axis, so I chose different sizes to have the circles actually visible, These are rx and ry
timeline = [0.0008 0.0012 0.0016 0.0020 0.0024 0.0028];
Orgidata =[79.8400 69.9390 50.0410 55.5082 34.5200 37.4486 31.4237 27.3532 23.2860 19.3039
79.7600 69.8193 49.8822 55.3115 34.2800 37.1730 31.1044 26.9942 22.8876 18.9061
79.6800 69.6996 49.7233 55.1148 34.0400 36.8975 30.7850 26.6352 22.4891 18.5084
79.6000 69.5799 49.5645 54.9181 33.8000 36.6221 30.4657 26.2762 22.0907 18.1108
79.5200 69.4602 49.4057 54.7215 33.5600 36.3467 30.1464 25.9173 21.6924 17.7133
79.4400 69.3405 49.2469 54.5249 33.3200 36.0714 29.8271 25.5584 21.2941 17.3159];
ry=1;
rx=0.0001;
dots=plot(timeline, Orgidata , '.');
hold on
for ix=1:size(Orgidata ,1)
for jx=1:size(Orgidata ,2)
rectangle('Position',[timeline(ix)-(rx/2),Orgidata(ix,jx)-(ry/2),rx,ry],'Curvature',[1,1],'EdgeColor',get(dots(jx), 'Color'));
end
end
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)