简体   繁体   English

如何将Matlab代码转换为图像?

[英]How can I convert matlab code to image?

For exmaple,I have the following code. 例如,我有以下代码。

% Generate random data from a uniform distribution
% and calculate the mean. Plot the data and the mean.

n = 50;            % 50 data points
r = rand(n,1);
plot(r)

% Draw a line from (0,m) to (n,m)
m = mean(r);
hold on
plot([0,n],[m,m])
hold off
title('Mean of Random Uniform Data')

for v = 1.0:-0.2:0.0
  disp(v)
end

I want to convert MATLAB code to an image. 我想将MATLAB代码转换为图像。

For example, if you copy the MATLAB code into a software then it return the image like this: 例如,如果将MATLAB代码复制到软件中,则它将返回如下图像:

在此处输入图片说明

How to do it? 怎么做?

If I use this code and publish it to PDF file,the code is not completely display. 如果我使用此代码并将其发布为PDF文件,则该代码不会完全显示。

sumLumi(x,y)=LLmap3(floor(x/4)+1,floor(y/4)+1)+LLmap3(floor(x/4)+2,floor(y/4)+1)+LLmap3(floor(x/4)+1,floor(y/4)+2)+LLmap3(floor(x/4)+2,floor(y/4)+2);

使用<code> SnapShot </ code>,您可以将整个页面复制到剪贴板

From the MATLAB editor you can Publish your document as a PDF (by changing the Output file format to pdf under publishing options). 在MATLAB编辑器中,您可以将文档发布为PDF(通过在发布选项下将输出文件格式更改为pdf)。 It will also evaluate the code unless you change the Publishing Options>Code Settings>Evaluate code to false . 除非您将发布选项>代码设置>评估代码更改为false否则它还将评估代码

The PDF can then can converted to an image (a quick google search gives an online PDF to JPG converter). 然后可以将PDF转换为图像(快速的Google搜索将在线PDF转换为JPG转换器)。

You can break a line and continue on the next with ... , for example 您可以换行,然后使用...继续下一行,例如

sumLumi(x,y)=LLmap3(floor(x/4)+1,floor(y/4)+1)+LLmap3(floor(x/4)+2,floor(y/4)+1)+LLmap3(floor(x/4)+1,floor(y/4)+2)+LLmap3(floor(x/4)+2,floor(y/4)+2);

can be written as 可以写成

sumLumi(x,y) = LLmap3(floor(x/4)+1, floor(y/4)+1) ...
               + LLmap3(floor(x/4)+2, floor(y/4)+1) ...
               + LLmap3(floor(x/4)+1, floor(y/4)+2) ...
               + LLmap3(floor(x/4)+2, floor(y/4)+2);

If you want to use Matlab only you can use this workflow: 如果只想使用Matlab,则可以使用以下工作流程:

  1. Make your code to be single .m file. 使您的代码成为单个.m文件。 Any text file will work. 任何文本文件都可以。
  2. Read this file in cell column vector Code ; cell列向量Code读取此文件;
  3. Process the lines adding using TeX or LaTeX formatting commands; 使用TeXLaTeX格式化命令处理添加的行;
  4. Create white figure with text(x,y,Code) ; text(x,y,Code)创建白色图形;
  5. Export the figure. 导出图。

This might be good way to produce many figures with same style. 这可能是产生许多具有相同样式的人物的好方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM