ismember legacy flag with older Matlab

6 次查看(过去 30 天)
If I use the legacy flag of ismember function in Matlab prior to 2012b like this
if ismember(A,B,'rows','legacy') do something... end
I get too many input arguments -error.
I'd like my code to work on both, earlier and newer Matlabs so how can omit the legacy flag if older matlab is used. I really don't want to make separate if-clauses in case of older and newer versions because there are so many of them.

采纳的回答

Friedrich
Friedrich 2014-8-25
Hi,
an IF clause is the only way here.
You could write your own small helper function which calls ismember and deals with the versions. So something like (haven't actually tried it but something like this should do it):
function [Lia,Locb] = myismember(A,B,flag)
if flag_was_provided AND MATLAB_version_is_smaller_than_8
[Lia,Locb] = ismember(A,B)
else
[Lia,Locb] = ismember(A,B,flag)
end
end
  2 个评论
Hoo Pee
Hoo Pee 2014-8-25
This is a nice answer but there's an additional problem that I encountered. Some built-in function also use the 'legacy' flag (see e.g., image function). Overriding all these function seems quite troublesome.
I can always make additional version and flag checks to the built-in ismember-function and put he modified function to my search path. I just have this nagging feeling that it will come back at me someday with nasty consequences.
Friedrich
Friedrich 2014-8-25
But the built in functions in 14a are not the same in 12a or so. Saying that the image function in 12a does not pass down the 'legacy' flag. So you don't have to worry about that.
You would need to adjust your code only and replace your ismember call with a dummy function which handles the argument conversion. Basically do NOT overload ismember. Only adjust your code to not call ismember directly.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by