2016-02-29 79 views
-1

我寫了matlab代碼,我想在word(.doc)文件中寫結果。我怎麼能夠? 我用下面的代碼,但不知道如何在word文件中寫'c'的值。其中c = a + b;如何用MATLAB代碼編寫微軟的word文件?

clc; 
word = actxserver('Word.Application'); 
word.Visible = 1; 
document = word.Documents.Add; 
selection = word.Selection; 
selection.TypeText('Hello world. '); 
selection.TypeText('My name is Professor Kitchin'); 
selection.TypeParagraph; 
selection.TypeText('How are you today?'); 
selection.TypeParagraph; 
selection.TypeText('Big Finale'); 
selection.Style='Heading 1'; 
selection.TypeParagraph; 
a=34; 
b=23; 
c=a+b; 
H1 = document.Styles.Item('Heading 1'); 
H1.Font.Name = 'Garamond'; 
H1.Font.Size = 20; 
H1.Font.Bold = 1; 
%H1.Font.TextColor.RGB=60000; % some ugly color green 

selection.TypeParagraph 
selection.TypeText('That is all for today!') 
document.SaveAs2([pwd '/test.docx']); 

所有除我不知道怎麼寫的C值在Word文件,就像我們在文本文件fprint打印變量的值是工作的罰款。

+0

我想你可以這樣做:http://uk.mathworks.com/products/ML_reportgenerator/或只是將它保存爲一個txt(無結構化文本)或CSV (結構化),然後使用msword轉換爲docx。 – GameOfThrows

回答

1

您能使用selection.TypeText(num2str(c))嗎?

+0

其工作。如果我想輸入「c的值是57」 – user36036

-1

回答你的第二個問題:

str2print=strcat('The value of c is ',num2str(c)); 

selection.TypeText(str2print)