4 May 2017

draw rectangle, polygon and circle in Matlab

收藏到CSDN网摘
To draw these shapes in Matlab, different ways could be used to achieve this. Write your own function to use plot(), or use rectangle() or use patch().

Pros:
The rectangle() can be used to draw ellipse, circle, round-corner rectangle as well if you specify the 'Curvature' parameter.

The plot() and patch() uses the same input as (x,y) list, which means x, and y are vectors of corresponding coordinates. You can use these two function draw polygons with any number of points.

Cons:
rectangle() uses input as [x,y,w,h] rather than (x,y) list. rectangle() can only accept input as a 4 elements vector. It requires calling of daspect([1,1,1]) to make the equality along each axis. However, it is very handy if you are drawing proper rectangle and circle.

15 Feb 2017

Close all messageboxes in Matlab

收藏到CSDN网摘
In matlab, user interaction could be easily achieved by using 'msgbox()' function. The format of calling the 'msgbox()' is: msgbox(msg,title,style,mode). It is also very useful to modify the 'style' parameters to customise the appearance of the message box. The build-in parameters are:
'none' - the default one if you didn't provide any parameter
'warn' - warning dialogue box
'help' - help dialogue box
'error' - error dialogue box

The last parameter 'mode' can be selected among 'modal', 'nonmodal', and 'replace'. Some examples are shown in the picture below.


But, how to close these dialogue boxes? You might though: are you kidding me? click on the button - that's as easy as breath. Yes, that's exactly what everyone will do for sure. Seriously, think about if you have hundreds, even thousands of these little evils created in a loop? - yeah, I know it's a bad idea to create these GUI elements in your code if you are doing something computational extensive. But I saw someone did this before. It might be a legacy code you are maintaining which never come across this warning before. Or you just started from a small dataset and need to debug in this way while you progresses gradually. It's even worse if you created these dialogue boxes using 'modal' mode - it means you can do nothing before closing them. That's the real nightmare!

Let's try to find a way of dealing with this!

21 Nov 2016

The Hardest 8-Puzzle

收藏到CSDN网摘
If you are working on any 8-puzzle related tasks, try your method with the following initial board which is considered to be the hardest to solve. Actually, it requires 31 moves to solve.

8 6 7
2 5 4
3 0 1

Someone may prefer empty/space rather than using 0. But the concept keeps the same.

8 Nov 2016

matplotlib tips: draw circle, rectangle, save figure and maxmize figure

收藏到CSDN网摘
matplotlib是一个非常强大的python库,拥有众多作图函数与matlab类似的语法,使用非常方便.但是经常有一些小问题需要处理.这里记下解决方案,涉及到: 画圆, 画矩形, 保存图片, 和图片默认最大化. 以后如果碰到其他问题再添加.

25 Oct 2016

批处理文件对字符串中空格的处理

收藏到CSDN网摘
在执行UG 2 ICEM tin几何模型转换时,文件路径带有空格时,处理不小心就会造成各种问题.以前写过UG2TIN的过程分析(见 链接1, 链接2).最近在没有部署ICEM或者没有Admin账户权限的机器上执行模型转换时遇到了各种问题.如之前分析过的,这个过程需要调用一个UG的probe函数来返回UG版本号,然后判断对应的vendor文件夹是否已经存在于ICEM的安装路径之中.由于UG版本更新非常快,远超ICEM,因此就造成ICEM的对应文件夹下找不到对应UG版本的vendor文件夹.被这个问题困扰了几周之后,决定重拾之前的分析,彻底搞清楚ug2tin的转换步骤.