Rank: 847 based on 128 downloads (last 30 days) and 7 files submitted
photo

Zhigang Xu

E-mail
Company/University
Bedford Inst of Oceanography

Personal Profile:

Professional Interests:

 

Watch this Author's files

 

Files Posted by Zhigang View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
05 Sep 2009 Published M-Files NUMUNIQUE Returns unique elements in an array and all the indices for the repetitious values. Author: Zhigang Xu sort, set, numunique, unique, mathematics 21 10
  • 5.0
5.0 | 2 ratings
28 Aug 2009 tidal_ellipse Consists of two tidal ellipse conversion programs Author: Zhigang Xu conversion, tidal ellipse, earth sciences, tools 21 1
  • 4.0
4.0 | 1 rating
28 Aug 2009 Published M-Files Converts between decimal integers to multiple based numbers Converts between decimal integers to multiple based numbers. Author: Zhigang Xu vectorization, data structure, computer science, binary tree search, mathematics 18 0
07 Jul 2008 Published M-Files Zero Out Smalls To zero out the small elements whose absolute values are smaller than a given criterion. Author: Zhigang Xu small quantities, eps, zeros 9 4
07 Jul 2008 Published M-Files ATAN2_SAFE To perform the same function as Matlab built-in function atan2 but safely guarded against erroneous Author: Zhigang Xu erroneous small input..., safe, inputs, builtin, mathematics, atan2 15 6
  • 1.0
1.0 | 2 ratings
Comments and Ratings by Zhigang View all
Updated File Comments Rating
06 Sep 2009 ATAN2_SAFE To perform the same function as Matlab built-in function atan2 but safely guarded against erroneous Author: Zhigang Xu

ATAN2 is fine if you can be watchful each time for its small inputs, whereas, as has been said above, "To relieve you from the cleaning burden every time when you need to call ATAN2, ATAN2_safe automates the cleaning and the calling two steps for you."

05 Sep 2009 NUMUNIQUE Returns unique elements in an array and all the indices for the repetitious values. Author: Zhigang Xu

Ah, the explanation to the above puzzle (i.e., NaN vs Double) lies in that whenever NaN is concatenated with other classes, it will be converted to zero first. Thus,

 uint8(nan)

ans =

    0

 int32(nan)

ans =

           0

[nan uint16([1 2])]

ans =

      0 1 2

whereas
[nan double([1 2])]

ans =

   NaN 1 2

A lesson to remember is that NaN is only a not-a-number within double class. It will become zero when it is converted to other classes.

05 Sep 2009 NUMUNIQUE Returns unique elements in an array and all the indices for the repetitious values. Author: Zhigang Xu

This is a very thoughtful suggestion. Thanks! I did a quick experiment as follows, showing that NaN can only work with a double class to get right logical indices. I will implement your suggestion for next updating. Thanks again!

>> diff([nan [0 1]])~=0

ans =

     1 1

>> diff([nan uint8([0 1])])~=0

ans =

0 1

04 Sep 2009 NUMUNIQUE Returns unique elements in an array and all the indices for the repetitious values. Author: Zhigang Xu

Matt,

Thanks for your comments and rating. Your suggestion can evidently make the codes more concise. However, using logical indexing is usually faster than FIND, as the Matlab Editor would advise. For this reason, I am hesitating to implement it for now. I tested your suggestion with a large input array (x=randi(999, 7e6,1)), and did not find any significant improvement in speed, although it did not go slower either. I am wondering if you can supply me your test script to show the significant difference in speed. I will be very happy to implement your suggestion after I understand why it can do so. Thanks!

Zhigang

04 Sep 2009 NUMUNIQUE Returns unique elements in an array and all the indices for the repetitious values. Author: Zhigang Xu

The updated version has been just up now (as 04-Sep-2009 11:09:21). So please feel free to download the new version. Thanks! --- Zhigang

Comments and Ratings on Zhigang's Files View all
Updated File Comment by Comments Rating
06 Sep 2009 ATAN2_SAFE To perform the same function as Matlab built-in function atan2 but safely guarded against erroneous Author: Zhigang Xu Xu, Zhigang

ATAN2 is fine if you can be watchful each time for its small inputs, whereas, as has been said above, "To relieve you from the cleaning burden every time when you need to call ATAN2, ATAN2_safe automates the cleaning and the calling two steps for you."

05 Sep 2009 NUMUNIQUE Returns unique elements in an array and all the indices for the repetitious values. Author: Zhigang Xu Xu, Zhigang

Ah, the explanation to the above puzzle (i.e., NaN vs Double) lies in that whenever NaN is concatenated with other classes, it will be converted to zero first. Thus,

 uint8(nan)

ans =

    0

 int32(nan)

ans =

           0

[nan uint16([1 2])]

ans =

      0 1 2

whereas
[nan double([1 2])]

ans =

   NaN 1 2

A lesson to remember is that NaN is only a not-a-number within double class. It will become zero when it is converted to other classes.

05 Sep 2009 NUMUNIQUE Returns unique elements in an array and all the indices for the repetitious values. Author: Zhigang Xu Xu, Zhigang

This is a very thoughtful suggestion. Thanks! I did a quick experiment as follows, showing that NaN can only work with a double class to get right logical indices. I will implement your suggestion for next updating. Thanks again!

>> diff([nan [0 1]])~=0

ans =

     1 1

>> diff([nan uint8([0 1])])~=0

ans =

0 1

05 Sep 2009 NUMUNIQUE Returns unique elements in an array and all the indices for the repetitious values. Author: Zhigang Xu Luong, Bruno

To make the function work for other integer class, I would suggest to modify the two lines:

d=diff([NaN; x]);
d=[true; d~=0];

to:

d=diff(x);
d=[true; d~=0];

Otherwise unexpected result is obtained with
[u p]=numunique(uint8([0 1]))

04 Sep 2009 NUMUNIQUE Returns unique elements in an array and all the indices for the repetitious values. Author: Zhigang Xu Xu, Zhigang

Matt,

Thanks for your comments and rating. Your suggestion can evidently make the codes more concise. However, using logical indexing is usually faster than FIND, as the Matlab Editor would advise. For this reason, I am hesitating to implement it for now. I tested your suggestion with a large input array (x=randi(999, 7e6,1)), and did not find any significant improvement in speed, although it did not go slower either. I am wondering if you can supply me your test script to show the significant difference in speed. I will be very happy to implement your suggestion after I understand why it can do so. Thanks!

Zhigang

Top Tags Applied by Zhigang
mathematics, earth sciences, atan2, binary tree search, builtin
Files Tagged by Zhigang View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
05 Sep 2009 Published M-Files NUMUNIQUE Returns unique elements in an array and all the indices for the repetitious values. Author: Zhigang Xu sort, set, numunique, unique, mathematics 21 10
  • 5.0
5.0 | 2 ratings
28 Aug 2009 tidal_ellipse Consists of two tidal ellipse conversion programs Author: Zhigang Xu conversion, tidal ellipse, earth sciences, tools 21 1
  • 4.0
4.0 | 1 rating
28 Aug 2009 Published M-Files Converts between decimal integers to multiple based numbers Converts between decimal integers to multiple based numbers. Author: Zhigang Xu vectorization, data structure, computer science, binary tree search, mathematics 18 0
17 Mar 2009 Screenshot SC - powerful image rendering Useful tool for rendering and outputting information rich images Author: Oliver Woodford colormap, color, render, image, greyscale, nans 276 15
  • 4.83333
4.8 | 12 ratings
07 Jul 2008 Published M-Files Zero Out Smalls To zero out the small elements whose absolute values are smaller than a given criterion. Author: Zhigang Xu small quantities, eps, zeros 9 4
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com