Stuart’s MATLAB Videos

Watch and Learn

Review of spiral puzzler

In the recent Puzzler about the spiral, most of the code that was produced went along the following:
  1. Create the spiral matrix
  2. Find the indices of the ‘1’s in the binary targets matrix
  3. Find the values of the spiral matrix at the indices from step 2
  4. Choose the lowest value and corresponding indices from step 3
  5. Create a look-up table for the deltaX and deltaY
  6. Use the indices from step 4 in the look-up tables
  7. Deal with the edge case
Most of these steps have been taught in the abstract at some point in the movies from this blog. Let’s review the skills used in the above algorithm. The second movie below is new content. 1.) Create the spiral matrix This is just a matter of typing out the matrix. This is covered incidentally in many videos. 2.) Find the indices of the ‘1’s in the binary targets matrix 3.) Find the values of the spiral matrix at the indices from step 2 The video on Absolute and Logical indexing covers these two steps. The most relevant part starts at 3:50.

4.) Choose the lowest value and corresponding indices from step 3 The MIN function works well here. 5.) Create a look-up table for the deltaX and deltaY This is a specialized matrix created most often with REPMAT. I cover how to make this look-up without REPMAT here along with other matrix creation skills in this new video.
6.) Use the indices from step 4 in the look-up tables This is covered in the same video as step 2. 7.) Deal with the edge case This is covered with an IF THEN statement. I made a video about SWITCH CASE statements that started out with IF THEN statements then converted them when it made better code.

|
  • print

コメント

コメントを残すには、ここ をクリックして MathWorks アカウントにサインインするか新しい MathWorks アカウントを作成します。