Posts

Showing posts with the label matlab

Matlab's Tip for tonight

Don't know type of variable in Matlab? use function >> classe( ) example >> class( 'thie amrko'); >> ans = >> char >> class(cell(1,1)); >> ans = >> cell

Cell Array Structure in Numpy

โอ้ว หลังจากpost ใน www.stackoverflow.com สักระยะ ระหว่างการเปลี่ยน code matlab ให้ เป็น python - numpy โดย มีปัญหาคือ cell array ใน matlab จะมาเป็น numpy structure ยังงัย ในที่สุดก็ได้คำตอบจากท่าน thrope ใน stackoverflow ได้แนะนำ linkไป http://docs.scipy.org/doc/scipy/reference/tutorial/io.html#matlab-cell-arrays และก็ได้บอกว่า ให้กำหนด dtype=numpy.object ตัวอย่างเช่น >>import numpy >>a = numpy.zeros((2,2),dtype=numpy.object) เท่านี้ เราจะสามารถเพิ่ม ค่าแบบใดๆ เข้าไปก็ได้เช่น >>a[0,0] = numpy.zeros((3,4)) >>a[0,1] = numpy.zeros((2,2)) ้hahahah มันยอดไปเลยไหมหละคับ

convert matlab's data to python's data

ขณะที่กำลัง debug เราสามารถใช้ command ที่ prompt K>> dlmwrite('yourfile.txt',Variable,'delimiter','\t','precision','%.6f','newline','pc') เป็นการ เขียนไฟล yourfile.txt โดยเอา ค่า ใน ตัวแปร matric Variable ที่มี delimiter คือ tabs ทศนิยม precision เป็น 6 ตำแหน่ง float ขึ้นบรรทัดใหม่สำหรับ pc