This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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')
    set(ax,'SortMethod','childorder')
end

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
else
    % execute code for R2014b or later
end

See Also

| | | | | | |