ส่งภาพจาก MATLAB ไปแสดงผลที่ PowerPoint ได้อย่างไร
MATLAB + PowerPoint
เราสามารถนำผลที่ได้จาก MATLAB ไปแสดงผลให้คนทั่วไป เครื่องอื่นๆที่ไม่มีโปรแกรม โดยสามารถให้ MATLAB ทำการ GENERATE REPORT ไปที่โปรแกรม Microsoft office อย่าง PowerPoint ได้
MATLAB CODE 1/2
import mlreportgen.ppt.* %Import the PPT package
ppt=Presentation(“testppt22.pptx”)
open(ppt);
slide=add(ppt,”Title and Content”);
- จาก Code ข้างต้น สามารถลำดับขั้นตอนได้ดังนี้
- ทำการ Import แพ็คเกจ PowerPoint หากไม่ทำการ Import เข้ามาจะไม่สามารถใช้ Built-in Function เกี่ยวกับ PowerPoint ได้
• ระบุชื่อ File PowerPoint ที่จะทำการ Generate Report เข้าไป แล้วเก็บไว้ในชื่อตัวแปรในตัวอย่างนี้ ขอตั้งชื่อว่า ppt
- ทำการ Add Outline ที่ PowerPoint จาก MATLAB ซึ่งจะมี 2 ส่วน คือ Title และ Content
MATLAB CODE 2/2
replace(slide,”Title”,”My Plot”);
figSnapshotImage=”figSnapshot.png”;
print(fig,”-dpng”,figSnapshotImage)
figPicture=Picture(figSnapshotImage);
replace(slide,”Content”,figPicture);
close(ppt)
rptview(ppt)
• ทำการ ระบุชื่อ Title ที่เราต้องการแสดงใน PowerPoint ซึ่งในที่นี้ขอกำหนดเป็น “My Plot”
• ตัวแปล fig ในที่นี้เป็นตัวแปรที่กำหนดไว้ให้เป็นชื่อตัวแปรของ figure ที่จะนำไปแสดงที่ PowerPoint สามารถสร้าง Format เพื่อทำการ Snapshot Image ตาม Code ข้างต้น
• สั่งปิด ppt ที่เราสร้างแล้วด้วยคำสั่ง close
- สามารภสั่งให้ PowerPoint ทำการเปิด เพื่อทำการดูผล Report ที่ MATLAB สร้างขึ้น
Code ตัวเต็มๆ จากกรณีกราฟที่ต้องการ Plot เป็น Mesh plot
z = peaks(25);
figure(3)
mesh(z)
fig=figure(3)
saveas(fig,’ppt1.jpg’)
import mlreportgen.ppt.* %Import the PPT package
ppt=Presentation(“testppt3.pptx”)
open(ppt);
slide=add(ppt,”Title and Content”);
replace(slide,”Title”,”My Plot”);
figSnapshotImage=”figSnapshot.png”;
print(fig,”-dpng”,figSnapshotImage)
figPicture=Picture(figSnapshotImage);
replace(slide,”Content”,figPicture);
close(ppt)
rptview(ppt)
สามารถติดตามเนื้อหาความรู้ต่างๆ โดยเฉพาะการใช้ประยุกต์ใช้กับโปรแกรม Matlab ได้ที่ Facebook Page : (13) Matlab bkk center | Facebook