Writing Code That Works in Multiple Releases

Most graphics code written in previous releases works with the graphics changes introduced in R2014b. However, there are some cases where code runs in one release and not in the other. If possible, implement an alternative that works across releases. If an alternative does not exist, then you can branch your code to execute different code paths.

Branch on Small Segment of Code

To leverage a small feature, such as a property, branch your code based on the existence of a specific feature. For example, SortMethod is an axes property introduced in R2014b. This code checks if the property exists before setting its value.

ax = gca;
if isprop(ax,'SortMethod')

Branch on Large Segment of Code

To branch large segments of code when there is no specific feature to test, use the verLessThan('matlab','8.4.0') command. This command returns 0 if you are running R2014b or later and returns 1 if you are running earlier releases. For example, use this coding pattern to branch your code.

if verLessThan('matlab','8.4.0')
    % execute code for R2014a or earlier
    % execute code for R2014b or later

See Also

| | | | | | |