Monday, December 23, 2013

How to rectify imagesc() axis in Matlab?

In Matlab, imagesc() and pcolor() are among the most used 2D plotting commands. For a given 2D matri, when you use the imagesc() command the y-axis comes inverted with respect to pcolor() command. To fix this issue and bring the y-axis increasing in positive y direction (with respect to screen plane), simply using axis xy is sufficient. Here is a small code snippet:


%% Difference between pcolor and imagesc
A=[ 1  2  3  4 7;
    5  6  7  8 -1; 
    9 10 11 12 3;
    2 3 4  6 7;
    9 10 11 12 3;
    1 2 7 -1 10;
    ];

figure (1); clf; set(gcf,'Color',[1 1 1]);
subplot(1,3,1);
pcolor(A); colorbar;
title('{\bf pcolor}(A)'); axis image;

subplot(1,3,2);
imagesc(A); colorbar;
title('{\bf imagesc}(A)'); axis image;

subplot(1,3,3);
imagesc(A); colorbar;
title('{\bf imagesc}(A) with {\bf axis xy}'); axis image;
axis xy
 


- For an earlier post on the difference of imagesc() and pcolor(), check here.
- Another post discusses the inclusion of grid lines to imagesc() here.

Friday, December 06, 2013

Night Train to Turkistan - Google Map of the Stuart Stevens and his company's trip along the Ancient Silk Road

Although the title is enticing, the book itself is not a great book. It focuses more on how the hotels they stayed were, the bus and train details and almost nothing about the culture and history of places they have passed. If you are reading to learn about the Turkistan and its people, this is not the book to do so. It is more about the daily practicality of their journey, how they found the bus/train where they sat and how it was etc. The author is obsessed to follow the route of Fleming without any particular reason and they cannot achieve that. Anyways, one of the nice part of the book is the map it has provided. I transferred it to Google Maps to see how the landscape they pass is and here is the link to that: (Opening the map in full screen mode is recommended)
e

Displaying grid lines in imagesc() function in Matlab


The default plot of pcolor() command in Matlab is to display the grid lines separating the each cell (top right figure below). One can use shading flat to remove the grid lines. However, for the imagesc() command, the default is not to show the grid lines (top left figure below). Below is  simple code snippet showing how to force imagesc() to have grid lines.

nx=4;
ny=4;
A=randn(nx,ny);

figure (8); clf; set(gcf,'Color',[1 1 1]);
subplot(2,2,1); 
imagesc(A); title('plain {\bf imagesc()}'); 
pbaspect([nx ny 1]);

subplot(2,2,2); 
pcolor(A);  title('plain {\bf pcolor()}')
pbaspect([nx ny 1]);

% With grid lines plotted
subplot(2,2,3:4); 
imagesc(A);
pbaspect([nx ny 1]);
title('{\bf imagesc()} with grid lines separating each cell')
set(gca,'xtick', linspace(0.5,nx+0.5,nx+1), 'ytick', linspace(0.5,ny+.5,ny+1));
set(gca,'xgrid', 'on', 'ygrid', 'on', 'gridlinestyle', '-', 'xcolor', 'k', 'ycolor', 'k');
- For an earlier post on the difference between pcolor() and imagesc(), click here.
- Note, syntax highligthing achieved by http://tohtml.com/matlab/

Thursday, December 05, 2013

Diffraction from a wedge - TMz case [FDTD simulation]


Here, we demonstrate the diffraction from a wedge when a plane wave with electric field component normal to the surface is impinging on it. The wedge corner acts as a secondary source to generate cylindrically propagating waves which are clearly seen when the scattered field plots on the right is analyzed. The left side of the animation shows the total field where both the scattered and incident fields are plotted together.





Beugung, Difracción, Diffrazione, Kırınım, 回折, Дифракция, Diffractie, Difração, 衍射, Dyfrakcja, Diffraktion, Interferenz, Interferencia

Saturday, September 28, 2013

How to Generate Animation Video using Matlab?

Let's say you have a mathematical function changing in time (or in any other quantity) and you would like to watch it progress and create an animation out of it. That is very simple to integrate into an existing Matlab code. Basically, by using the mov and getframe(), addframe() commands, one can easily generate the animation file. Below is a sample code snippet for further reference:


mov = avifile('test.avi','fps',7,'quality',100,'keyframe',1);
     
     
    figure('Renderer','zbuffer')
    Z = peaks;
    surf(Z);
    axis tight
    set(gca,'NextPlot','replaceChildren');
    % Preallocate the struct array for the struct returned by getframe
    F(20) = struct('cdata',[],'colormap',[]);
    % Record the movie
    for j = 1:200
        surf(.01+sin(2*pi*j/20)*Z,Z)
        F(j) = getframe;
     
        F = getframe(gcf);
        mov = addframe(mov,F);
     
        pause(0.1);
    end
     
    mov = close(mov); 





Note: I used the following website to obtain the highlighted Matlab code in html: http://tohtml.com/matlab/

Monday, September 02, 2013

Hacı Münib Engin Noyan'ın Hatıratından bir Anı


Hacı Münib Engin Noyan'ın hayatını anlattığı Fatma Güzey'in sunduğu televizyon programında bahsettiği çarpıcı bir anısı var ki, yazıya dökülmesi belki daha çok kişinin duymasına, öğrenmesine vesile olacağı için burada transkriptini çıkarmaya çalıştım. Yorumsuzca aktarıyorum:



...
[Noyan] Bir aile dostumuz - Allah taksiratını affetsin - Prof. Dr. Max Neineke (?) ben daha 16 yaşlarında iken falan bana bir sual sormuştu. Demişti ki "Berlin'de ne oynuyor tiyatroda?".... Biliyorum... "Londra'da ne oynuyor?"... Biliyorum. Çünkü gazetelerden [biliyorum]. "Peki" dedi, "Atina da ne oynuyor?" dedi [Bilmiyorum anlamına gelen yüz ifadesi]

[Güzey] Yunanistanla çok bir şeyiniz yok... bağlantınız...

[Noyan] "Şam'da ne oynuyor? [yine cevap yok]. Bağdad'da ne oynuyor? E sen kendi coğrafyanı tanımıyorsun. Onları [batıyı] tanıyorsun. Biri burnunun dibi. Şam'da tiyatro var mı yok mu onu bile bilmiyorsun. Böyle bir şey olur mu?" dedi bana.

[Güzey] E yönümüz tamamen Avrupa'ya döndürülmüş, altta ne var yanda ne var bilmiyoruz

[Noyan] Ve şu muazzam cümleyi kullandı. Dedi ki "Siz, Türkler" dedi, "Çok aptalsınız".... Sinirlendim tabi. Niye aptal diyorsun ki bana yani? Niye? dedim. "Çünkü" dedi. "Siz doğudan gelen trenin lokomotifi olmak yerine, batıya giden trenin son vagonu olmayı tercih ettiniz." dedi.

[Güzey] Çok güzel bir cümle..

[Noyan] Muazzam bir cümle.. ...
Doğudan gelen medeniyet treninin lokomotifi olmak varken, ki bizim hala da konumumuz o,  elhamdulillah - batıya giden trenin son vagonu olduk. En arkada hayvanları koydukları, uyduruk... Sallana sallana gidip serseme dönmüş

[Güzey] Her an kopma tehlikesi ile de karşı karşıya olan

[Noyan] Evet, birinci sınıf vagon bile olamadık. En son vagon...


.......



Programın tamamının linki (yukarıdaki kısım için 27:00'dan itibaren dinleyebilirsiniz):
http://youtu.be/H8CiJ9XD0sQ

Engin Noyan'ın resmi web sitesi:
http://enginnoyan.com.tr/

Sunday, August 25, 2013

Mohammad Hosayn Farahani's Hajj Travel Route (1885-86)


View Mohammad Hosayn Farahani's Hajj Travel Route (1885-86) in a larger map

Adopted from "The Safarnameh of Mirza Mohammad Hosayn Farahani", from his pilgrimage in 1885-1886.

Farahani's journey to Mecca not only fulfills his pilgrimage obligation but also provides a detailed guidebook for his contemporary Persians needed for their Hajj travels. Thanks to the introduction of railroads between Baku and Batumi, Farahani takes the unconventional route to Mecca, traveling first to Batumi via train and then going to Istanbul by boat stopping along the route in several cities such as Trabzon and Sinop. After Istanbul, he continues his journey by boat to reach Alexandria over the Aegean Sea and from thereon to Jidda via Suez Canal. His return trip was also from the same route and his book was considered to be Guide Michelin of his time for round-trip Persian Hajj.

Sunday, August 11, 2013

Bridge Pedal - 6 Bridge loop

Bridge Pedal - 6 Bridge Loop



Over the weekend, I had the chance to attend the annual Bridge Pedal Event in downtown Portland. There are several routes of various lengths and I chose the 13 miles crossing the 6 bridges. The event is very well organized and good for families. Definitely recommended! Below are some snapshots from my route.



The union station:

Broadway Bridge:

Finish line:

King's Mountain - Sea of Clouds

King's Mountain - Sea of Clouds



King's Mountain is one of the most popular hiking destination for Oregonians especially those living in the "weird" Portland and vicinity. Among many of our hikes to King's Mountain, this one was particularly spectacular when we got closer to the peak. The thick clouds left below formed a virtual blanket over the Tillamook Forest. It almost felt like a sea of clouds. Here are some photos from the day:





King's Mountain on another day

Wednesday, June 26, 2013

Map of Nasir Khusraw's Travels (1046-1052)


View Nasir Khusraw's Travels (1046-1052) in a larger map


Adapted from the Naser-e Khosraw's Book of Travels, W. M. Thackston, Jr. New York, 1986

Nasir Khusraw's Safarname (Book of Travels) has been a classical text for Persian travel writing for the last 1000 years. Confessing that his travels are due to mid life crisis, he set out for Mecca at the age 42 after seeing a dream while in a drunk situation. In his dream, he was pointed the qibla direction (Mecca) when he asks about where the wisdom lays. Following this, he resolves to go for Hajj and rather immediately sets our for Mecca. For the next seven years, he travels through Persia, West Azerbaijan, Turkey, Syria, Cairo, Hijaz, Hafsa and Basra region.