How can I quickly find the difference in function usage between different MATLAB versions? For example, the Name-Value Arguments "QuoteStrings" of the function writetable

2 次查看(过去 30 天)
On the version of MATLAB 2021b, the following code is correct:
writetable(mytable,'result.csv','Delimiter',',','QuoteStrings',0)
However, the same code cannot run on my friend's computer. The version of MATLAB on his computer is 2022b.
From the official help document, we can see that the name value parameter "QuoteStrings" has modified the value parameter.
Previous version:
% 'QuoteStrings' A logical value that specifies whether to write
% text out enclosed in double quotes ("..."). If
% 'QuoteStrings' is true, any double quote characters that
% appear as part of a text variable are replaced by two
% double quote characters.
Latest version:
% "QuoteStrings" - A flag which specifies when to quote output text.
% - "minimal" (default) Any variables which contain
% the delimiter, line ending, or the double-quote
% character '"' will be quoted.
% - "all" All text, categorical, datetime, or
% duration variables will be quoted.
% - "none" No variables will be quoted.
Therefore, in order to avoid differences between different MATLAB versions, I can only change the code to:
try
writetable(mytable,'result.csv','Delimiter',',','QuoteStrings',0)
catch
writetable(mytable,'result.csv','Delimiter',',','QuoteStrings','none')
end
Similar situations are often encountered in many other functions. Many name-value parameters may be proposed in a newer version, but the MATLAB official website does not provide relevant compatibility suggestions.
For example, the 'CData' parameter in the bar function will report an error in MATLAB2017a.
So, what's a good way to quickly know the modification of a function? I hope you can give some good suggestions or share your experience. Thank you.

采纳的回答

Rik
Rik 2023-2-28
编辑:Rik 2023-3-1
A few releases ago Mathworks introduced a changes section at the bottom of the documentation page. Other than that, it is simply a case of comparing documentation pages.
There is no standard way. There is a reason I keep my ifversion function on the file exchange up to date. Instead of try catch blocks (which can get messy, especially with multiple options), I use ifversion to branch my code. That way any errors will keep making sense (your code can throw an error about the parameters if there is a file access error on releases where you need the version in the try section).
Edit so it doesn't get lost (thanks Steven, I will try to remember to suggest them in on the FEX description page):
If you don't want to include ifversion in your code, you can probably use either verLessThan (introduced in release R2007a) or isMATLABReleaseOlderThan (introduced in release R2020b).
  7 个评论
Steven Lord
Steven Lord 2023-3-1
You could use verLessThan (introduced in release R2007a) or isMATLABReleaseOlderThan (introduced in release R2020b) to check if the release of MATLAB you're using is too old or new to have a particular function or piece of functionality, assuming you only need to check back to release R2007a or release R2020b respectively. This could avoid users to whom you provide your code needing to install ifversion from the File Exchange.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Client Programming 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by