I'm trying to create a video from my data using Matlab animated lines function. Code is working fine but I'm not getting axis values in the final output. Can anyone please help me. Here I have attached my code:
clc
clear
close all
%%xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
leftX=[0 -0.081205 -0.16242 -0.24363 -0.32485 -0.40606 -0.48727 -0.56849 -0.6497 -0.73091 -0.81213 -0.89334 -0.97455 -1.0558 -1.137 -1.2182 -1.2994 -1.3806 -1.4618 -1.543 -1.6243 -1.7055 -1.7867 -1.8679 -1.9491 -2.0303 -2.1115 -2.1928 -2.274 -2.3552 -2.4364 -2.5176 -2.5988 -2.68 -2.7612 -2.8425 -2.9237 -3.0049];
leftY=[45.281 51.25 48.898 59.386 49.465 62.04 50.664 53.231 63.503 53.371 55.802 59.646 56.474 56.683 57.956 56.628 56.925 57.331 56.525 56.857 57.245 56.807 56.973 57.035 56.859 56.993 57.126 57.126 57.012 57.046 57.112 57.144 57.079 57.045 56.927 57.089 57.134 57.012];
rightX=[0.000 0.081 0.162 0.244 0.325 0.406 0.487 0.568 0.650 0.731 0.812 0.893 0.975 1.056 1.137 1.218 1.299 1.381 1.462 1.543 1.624 1.706 1.787 1.868 1.949 2.030 2.112 2.193 2.274 2.355 2.436 2.518 2.599 2.680 2.761 2.843 2.924 3.005];
rightY=[45.281 51.212 48.869 59.459 49.138 62.068 50.844 52.928 63.230 53.481 55.907 59.519 56.434 56.849 57.779 56.599 57.046 57.256 56.714 56.974 56.936 56.936 57.113 56.924 56.941 56.908 57.044 56.847 56.952 57.008 56.947 57.041 57.038 56.910 56.858 57.093 57.034 56.928];
%animate function
h=animatedline('Color','r','LineWidth',2.5);
axis([-2.0 2.0 40 70]);
h2=animatedline('LineWidth',2.5);
box on
set(gca, 'FontSize', 1.20, 'LineWidth', 1.2);
ylabel(' O^{2-}ion density(ion/{nm}^3)', 'FontSize', 20);
xlabel('Distance from GB core(nm)', 'FontSize', 20);
frames= cell(length(leftX)+20,1)
%define forloop
for i=1:length(leftX)
addpoints(h,leftX(i),leftY(i));
addpoints(h2,rightX(i),rightY(i))
drawnow; pause(1.3)
frame(i)=getframe(gcf);
end
obj =VideoWriter('oscillations.avi');
obj.Quality=100;
obj.FrameRate =1;
open(obj);
for i=1:length(leftX)
writeVideo(obj,frame(i));
end
obj.close()
It just comes from your call to
set(gca, 'FontSize', 1.20, 'LineWidth', 1.2);
The tick labels are there, but they are very very small. Try increasing the 'Fontsize' value you impose, e.g.:
set(gca, 'FontSize', 5, 'LineWidth', 1.2);
Related
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 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 followed this tutorial Acquire Images from Webcams but when I make the preview of the image with
preview(cam) the image appears small and i want the image in fullscreem.
I have proved with set(gcf,'units','normalized','outerposition',[0 0 1 1]) but it doesnt work.
How can I expand the preview image? Thanks a lot
Finally I found a solution. I hope it is useful for someone
%% Create a webcam object called cam
cam = webcam;
cam.Resolution = '1280x720';
dimensions = get(0, 'ScreenSize'); %your screem
figure('Toolbar','none',...
'Menubar', 'none',...
'NumberTitle','Off',...
'Position', [1 1 dimensions(3) dimensions(4)], ... % Position, pixels[x, y, width, height]
'Name','My Preview Window');
hImage = image(zeros(720, 1280, 3));
preview(cam, hImage);
I am currently working on adding annotations to satellite images in MATLAB. Since the color underneath each text field can vary quite a lot, I want to use a background color under the text to make it easier to see and read.
However, when I do this, a lot of the terrain gets obscured. I though of trying to make the background color for each text box semi transparent, but hit a dead end trying to come up with a solution.
Any ideas? I was hoping for some UI-element where I could just set the 'facealpha' to maybe 0.5. I also need the text to support being rotated (as can be seen in the examples below).
Below is some example code and the resulting image. The workspace with the satellite data can also be found in the link:
Example workspace
figure(1);clf
imagesc(xx,yy,Map);
hold on
plot(xInspection,yInspection,'g.-')
% # Two ways of making a rotated text annotation.
% # Cant make background semi-transparent
testAnno= annotation('textarrow',[0.5 0.5],[0.5 0.5], ...
'string','textarrow annotation', ...
'HeadStyle','none','LineStyle', 'none',...
'TextRotation',asin(directionVec(1))*180/pi,...
'TextBackgroundColor',[0.7 0.7 0.7]);
testText = text(mean(xInspection),mean(yInspection),'text annotation', ...
'rotation',asin(directionVec(1))*180/pi, ...
'HorizontalAlignment','right', ...
'color',[0 0 0], ...
'backgroundcolor',[0.7 0.7 0.7], ...
'fontsize',8);
It doesn't look like either annotation or text return HgObjects that have BackgroundAlpha properties (they might exist but I wasn't able to find them using getundoc or by trying various different hacks).
I was able to get something working by drawing the background myself. Here is a simple proof of concept:
f = figure;
tObj = text(.5, .5, 'text object', 'FontSize', 20);
set(gca,'XLimMode', 'manual', 'YLimMode', 'manual'); % prevent the axes from resizing automatically
p = get(tObj, 'Extent'); %Get the outer position of the text
% now create a patch around the text object
pObj = patch([p(1) p(1) p(1)+p(3) p(1)+p(3)], [p(2) p(2)+p(4) p(2)+p(4) p(2)], 'r');
uistack(tObj, 'top'); % put the text object on top of the patch object
set(pObj , 'FaceAlpha', .2); % set the alpha of the patch face to .2
%Rotate the objects
set(tObj, 'Rotation', 20);
rotate(pObj, [0 0 1], 20);
I am afraid the only way you can do this is by not setting any color to your annotations, and then placing a patch in the background of each annotation. So something like this:
% Use completely transparent annotations
hA = annotation('textarrow', ..., 'TextBackgroundColor', 'none')
% Place a transparent patch exactly in the background of your annotation
hP = patch(X, Y, 'white', 'EdgeColor', 'none', 'FaceColor', 'white', ...
'alpha', 0.3)
% Ensure that your annotation is on top
uistack(hA, 'top')
But of course the big problem is to determine the correct coordinates of the patch (X and Y). Rotating is easy by simply multiplying your coordinates by a rotation matrix. However, finding the length and height of the patch and its central location is not that easy. You might be able to find some useful functions for this at Matlab central...
Introduction
I'm trying to emphase some region on a spherical surface saying that this region should be colored as not transparent (alpha = 1.0) and other parts of the sphere should be colored as semi-transparent (alpha = 0.5).
Problem
Considering WAlpha(Data >= DummyValue) = 1.0 and WAlpha(Data < DummyValue) = 0.5, the following command does not work as expected:
surf(X, Y, Z, Data, 'AlphaData', WAlpha, 'FaceAlpha', 'interp');
It draws all non-selected region as fully-transparent:
Note
I have no issue when setting 'FaceAlpha' to scalar value (i.e its not an issue with my graphic card):
surf(X, Y, Z, Data, 'AlphaData', WAlpha, 'FaceAlpha', 0.5);
Source code
Here is the link to the very short and dummy code I created to reproduce the issue: link
Please let me know if you have any other idea for emphasing selected region rather than using transparency.
Here is quick test:
%# surface data
Z = membrane;
%# alpha-transparency matrix
A = ones(size(Z))*0.3; %# transparent by default
A(abs(Z)>0.5) = 1; %# make certain region opaque
%# plot
figure('Renderer','opengl')
surf(Z, 'AlphaData',A, 'AlphaDataMapping','none', ...
'FaceAlpha','interp', 'EdgeColor','none')
Result:
Ooops, found it...
One needs to change the Alim property on axes object because it is improperly set to [min(WAlpha) max(WAlpha)] when setting AlphaData instead of keeping [0 1]. So the command is:
surf(X, Y, Z, Data, 'AlphaData', WAlpha, 'FaceAlpha', 'interp');
alim([0 1]);