在Excel中打印并调整MATLAB图形大小 [英] Print and resize MATLAB figure in Excel

查看:229
本文介绍了在Excel中打印并调整MATLAB图形大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MATLAB中有两个数字,其中包括句柄 hFig1 hFig2 。我想将它们打印到Excel中的特定单元格(单元格E3和I3),并将它们重新整形为每个[2in x 3in]。



我已经尝试使用 .AddPictures 对象处理程序并使用 print -dmeta ,但我找不到一种实现我所有三个目标的方法



我也在同时将数据写入excel,因为有很多数据行被发送,我希望有一个方法没有需要使用ActiveXServer持续调用excel。



有没有人对这种问题有一个很好的方法或资源?

解决方案

您可以将MATLAB数字最容易地添加到Excel中:

 %创建一些任意图形
f1 =图;峰; f2 = figure;膜;

%连接到Excel,使其可见并添加工作表
xl = actxserver('Excel.Application');集(XL,可见,1);
xl.Workbooks.Add(1); xls = xl.ActiveSheet;

%粘贴在MATLAB图中
print(f1,'-dbitmap'); xls.Range( E3’ )PasteSpecial的。
print(f2,'-dbitmap'); xls.Range( I3’ )PasteSpecial的。

我不确定你的意思是通过3in制作图像2in。是屏幕上的大小吗?在什么决议?或者是打印时的尺寸?



您可以直接在中指定图像的大小和位置:

  xls.Shapes.Item(1).PictureFormat.CropLeft = 30; 
xls.Shapes.Item(1).PictureFormat.CropRight = 30;
xls.Shapes.Item(1).Height = 200;
xls.Shapes.Item(1).Left = xls.Range('E3')。

但是,如果您希望以英寸为单位,您需要一种转换为积分的方法,具体取决于



你提到你不断地用 actxserver 调用Excel;每次写每条数据时,您是否一次又一次地连接?您可能不需要这样做 - 更有可能保持单个连接打开并写入每个数据,然后保存文件并关闭连接。



Excel对象模型的一个很好的参考资源是Microsoft 文档。这不是一个简单的阅读:)


I have two figures in MATLAB with the handles hFig1 and hFig2. I would like to print them to specific cells in Excel (cells E3 and I3) and reshape them to each be [2in x 3in].

I have tried using the .AddPictures object handler and using print -dmeta, but I can't find a way to achieve all three of my objectives.

I am also writing data to excel at the same time and because there is a lot of data lines being sent, I was hoping to have a method that didn't require continually invoking excel with the ActiveXServer.

Does anyone have a good method or resource for this kind of problem?

解决方案

You can add MATLAB figures to Excel most easily like this:

% Create some arbitrary graphics
f1 = figure; peaks; f2 = figure; membrane;

% Connect to Excel, make it visible and add a worksheet
xl = actxserver('Excel.Application'); set(xl,'Visible',1);
xl.Workbooks.Add(1); xls = xl.ActiveSheet;

% Paste in the MATLAB figures
print(f1, '-dbitmap'); xls.Range('E3').PasteSpecial;
print(f2, '-dbitmap'); xls.Range('I3').PasteSpecial;

I'm not sure exactly what you mean by making the images 2in by 3in. Is that the size on screen? At what resolution? Or is it the size when printed?

You can specify the size and position of the image in points directly:

xls.Shapes.Item(1).PictureFormat.CropLeft  = 30;
xls.Shapes.Item(1).PictureFormat.CropRight  = 30;
xls.Shapes.Item(1).Height  = 200;
xls.Shapes.Item(1).Left = xls.Range('E3').Left;

But if you want it in inches you'll need a way of converting to points, depending on the way it's displayed.

You mention that you're continually invoking Excel with actxserver; are you connecting over and over again each time you write each piece of data? You probably don't need to do that - more likely you could keep a single connection open and write each piece of data to it, then save the file and close the connection.

A good reference resource for the Excel Object Model is the Microsoft documentation. It's not an easy read though :)

这篇关于在Excel中打印并调整MATLAB图形大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆