MATLAB Diagrams
Create paper-quality vector graphics geometry diagrams in 2D and 3D
- Angle Arc
- Arrow
- Circle
- Cone
- Cylinder
- Cylinder Line (for connecting two cylinders)
- Dot
- Line
- Perpendicular Mark
- Plane
- Robot Diagram (compatible with general-robotics-toolbox)
- Sphere
- Text
Download the library code and make sure the +diagrams
folder is inside a folder in the MATLAB path.
Example code is shown in usage.m
, as well as in the examples
folder.
Set up a new figure by running h_fig = diagrams.setup()
. Then, add graphics objects to the figure by calling the diagrams library, or by using matlab functions like plot
and plot3
.
Certain graphics objects must be redrawn depending on the camera angle. At the end of your script, you should call diagrams.redraw()
. You can also press any keyboard key to call diagrams.redraw()
if you're moving the camera position interactively.
To export the figure, call diagrams.save(h_fig, name, location)
. This will save the figure in both .eps
and .svg
format.
The figure is designed to be displayed 3.5 in wide to fit the width of an IEEE journal article. However, there is a 2x scaling factor so that the MATLAB figure window is a reasonable size on a computer screen. To include the figure in LaTeX, you should use \includegraphics[scale=0.5, clip]{diagram.eps}
. Adding clip
makes sure any white space doesn't overlap with text.
If you're submitting to arXiv and want to use pdfLaTeX, you will need to convert the eps
files to pdf
files. arXiv doesn't do this conversion. If you have miktex installed, run the command
miktex-epstopdf --outfile=diagram-converted-to.pdf diagram.eps
Or, run the following bash file on Windows:
for %%I in (*.eps) do (
miktex-epstopdf --outfile="%%~nI-converted-to.pdf" "%%I"
)
Then, you can include the PDF file using \includegraphics[scale=0.5, clip]{diagram-converted-to.pdf}
To make sure the gif stays the same size, make a rectangle that fills the whole frame.
annotation('rectangle',[0 0 1 1]);
You may want to use campos()
, camva()
, and camtarget()
to lock the camera view.
At the end of the animation loop, use exportgraphics
to save each frame to a file.
exportgraphics(gca, "filename.gif", "Append", i ~= 1)
This method gives more control over delay time and other options.
filename = "file_name.gif";
clear im
for i = 1:N
% Code here
frame = getframe(h_fig);
im{i} = frame2im(frame);
end
for idx = 1:length(im)
[A, map] = rgb2ind(im{idx}, 256);
if idx == 1
imwrite(A, map, filename, "gif", "LoopCount", Inf, "DelayTime", 0.5);
else
imwrite(A, map, filename, "gif", "WriteMode", "append", "DelayTime", 0.5);
end
end
If you have any improvements you'd like to make, or even ideas or requests for improvements, please start a GitHub issue.
引用格式
Alex Elias (2024). MATLAB Diagrams (https://github.com/aelias36/matlab-diagrams/releases/tag/v1.1.0), GitHub. 检索时间: .
MATLAB 版本兼容性
平台兼容性
Windows macOS Linux标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!+diagrams
+diagrams/+utils
+diagrams/+utils/+ds2fig
examples
版本 | 已发布 | 发行说明 | |
---|---|---|---|
1.1.0 | See release notes for this release on GitHub: https://github.com/aelias36/matlab-diagrams/releases/tag/v1.1.0 |
||
1.0.0 | See release notes for this release on GitHub: https://github.com/aelias36/matlab-diagrams/releases/tag/v1.0.0 |