简体   繁体   中英

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.

For example, if you copy the MATLAB code into a software then it return the image like this:

在此处输入图片说明

How to do it?

If I use this code and publish it to PDF file,the code is not completely display.

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). It will also evaluate the code unless you change the Publishing Options>Code Settings>Evaluate code to false .

The PDF can then can converted to an image (a quick google search gives an online PDF to JPG converter).

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:

  1. Make your code to be single .m file. Any text file will work.
  2. Read this file in cell column vector Code ;
  3. Process the lines adding using TeX or LaTeX formatting commands;
  4. Create white figure with text(x,y,Code) ;
  5. Export the figure.

This might be good way to produce many figures with same style.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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