Rank: 1634 based on 36 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 MATLAB Files NUMUNIQUE Returns unique elements in an array and all the indices for the repetitious values. Author: Zhigang Xu sort, unique, set, numunique, mathematics 1 10
  • 5.0
5.0 | 2 ratings
28 Aug 2009 tidal_ellipse Consists of two tidal ellipse conversion programs Author: Zhigang Xu tools, conversion, tidal ellipse, earth sciences 13 1
  • 4.0
4.0 | 1 rating
28 Aug 2009 Published MATLAB Files Converts between decimal integers to multiple based numbers Converts between decimal integers to multiple based numbers. Author: Zhigang Xu mathematics, data structure, binary tree search, computer science, vectorization 0 0
07 Jul 2008 Published MATLAB Files Zero Out Smalls To zero out the small elements whose absolute values are smaller than a given criterion. Author: Zhigang Xu small quantities, zeros, eps 1 4
07 Jul 2008 Published MATLAB Files ATAN2_SAFE To perform the same function as Matlab built-in function atan2 but safely guarded against erroneous Author: Zhigang Xu atan2, erroneous small input..., builtin, inputs, mathematics, safe 1 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
12 Oct 2011 FDATENUM_etc A package offers much fast versions for datenum, datevec, and str2num. Author: Zhigang Xu Eran

I tested fstr2num with a large string (>1,000,000) of numbers such as: 11 44 44 11 33 13 33 22 11 44. Separated by a single space. str2num takes 3-4 seconds to convert them to numeric. fstr2num took less than a second, but it produced many more numbers than actually are, probably breaking some of the numbers to single numbers (1 2 3 4).

In short, it doesn't work well. hope you can fix it because the world needs it!

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]))

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
20 Aug 2010 Screenshot SC - powerful image rendering Useful tool for rendering and outputting information rich images Author: Oliver Woodford color, colormap, height map, render, colorbar, mask 97 37
  • 4.86364
4.9 | 22 ratings
05 Sep 2009 Published MATLAB Files NUMUNIQUE Returns unique elements in an array and all the indices for the repetitious values. Author: Zhigang Xu sort, unique, set, numunique, mathematics 1 10
  • 5.0
5.0 | 2 ratings
28 Aug 2009 tidal_ellipse Consists of two tidal ellipse conversion programs Author: Zhigang Xu tools, conversion, tidal ellipse, earth sciences 13 1
  • 4.0
4.0 | 1 rating
28 Aug 2009 Published MATLAB Files Converts between decimal integers to multiple based numbers Converts between decimal integers to multiple based numbers. Author: Zhigang Xu mathematics, data structure, binary tree search, computer science, vectorization 0 0
07 Jul 2008 Published MATLAB Files Zero Out Smalls To zero out the small elements whose absolute values are smaller than a given criterion. Author: Zhigang Xu small quantities, zeros, eps 1 4

Contact us at files@mathworks.com