简体   繁体   English

Matlab剪贴板精度-长格式-

[英]Matlab Clipboard Precision - Format long -

I need to copy paste several matrix from matlab to excel so i did my researches and i've found a really amazing script called num2clip that brings the selected array to the clipboard. 我需要从matlab复制粘贴几个矩阵到excel,所以我进行了研究,我发现了一个非常了不起的脚本num2clip,它将选定的数组带到剪贴板。 The only problem is that the numbers format is short, when i would like it to be long. 唯一的问题是,数字格式很短,而我希望它很长。 I suspect the "double" type used in the script but i'm still new to matlab so i do have some important lacks. 我怀疑脚本中使用了“ double”类型,但是我还是matlab的新手,所以我确实有一些重要的不足。

Here is the script that i've found, what do i have to do according to you in order to keep the long input format ? 这是我找到的脚本,为了保持长输入格式,我必须根据您做什么?

function arraystring = num2clip(array)

function arraystring = num2clip(array)

%NUM2CLIP copies a numerical-array to the clipboard
%   
%   ARRAYSTRING = NUM2CLIP(ARRAY)
%   
%   Copies the numerical array ARRAY to the clipboard as a tab-separated
%   string.  This format is suitable for direct pasting to Excel and other
%   programs.
%   
%   The tab-separated result is returned as ARRAYSTRING.  This
%   functionality has been included for completeness.
%   
%Author: Grigor Browning
%Last update: 02-Sept-2005

%convert the numerical array to a string array
%note that num2str pads the output array with space characters to account
%for differing numbers of digits in each index entry
arraystring = num2str(array); 

%add a carrige return to the end of each row
arraystring(:,end+1) = char(10);

%reshape the array to a single line
%note that the reshape function reshape is column based so to reshape by
%rows one must use the inverse of the matrix
%reshape the array to a single line
arraystring = reshape(arraystring',1,prod(size(arraystring))); 

%create a copy of arraystring shifted right by one space character
arraystringshift = [' ',arraystring]; 

%add a space to the end of arraystring to make it the same length as
%arraystringshift
arraystring = [arraystring,' ']; 

%now remove the additional space charaters - keeping a single space
%charater after each 'numerical' entry
arraystring = arraystring((double(arraystring)~=32 |...
          double(arraystringshift)~=32) &...
          ~(double(arraystringshift==10) &...
          double(arraystring)==32) );

%convert the space characters to tab characters
arraystring(double(arraystring)==32) = char(9); 
format long e

%copy the result to the clipboard ready for pasting
clipboard('copy',arraystring); 

Best regards. 最好的祝福。

Just replace the line with: 只需将行替换为:

arraystring = num2str(array) ; 

to a line like that: 像这样的一行:

arraystring = num2str(array,'%15.15f') ;

This will give you the maximum precision you can reach with the double type (15 digits). 这将为您提供double精度类型(15位数字)可以达到的最大精度。

Look at the num2str documentation for more custom format. 请参阅num2str文档以获取更多自定义格式。

Thank you Hoki for your participation. 谢谢Hoki的参与。 I didnt had the time to go through all the documentation wich is great by the way. 顺便说一下,我没有时间仔细阅读所有文档。 When i tried your solution, the copied data was all inserted on one cell, i just had to change : arraystring = num2str(array,'%15.15f') ; 当我尝试您的解决方案时,复制的数据全部插入到一个单元格中,我只需要更改:arraystring = num2str(array,'%15.15f'); to arraystring = num2str(array,15) ; 到arraystring = num2str(array,15);

Have a nice day ! 祝你今天愉快 !

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

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