필터 지우기
필터 지우기

MEX and Matlab - Check if an output is skipped/unused, i.e. marked with tilde (~)

조회 수: 1 (최근 30일)
Alex R.
Alex R. 2015년 2월 7일
댓글: Bernt Nilsson 2018년 6월 13일
Hi,
Is there a way in the MEX API to check whether an output was skipped, i.e. marked with a tilde (~)? Specifically, suppose I do:
[~,y]=myfunc(x);
In MEX, nlhs is set to 2. Is there a way to determine that plhs[0] is unwanted?
How about in Matlab .m code? I could then write a wrapper accordingly for the myfunc mex file (not ideal, but would work).
Cheers, Alex.
p.s. I have already seen this (and am aware I could write separate functions, but it would be infinitely better to detect the tilde)
  댓글 수: 1
Bernt Nilsson
Bernt Nilsson 2018년 6월 13일
I have the same problem, and three years have passed. Is it yet possible to detect the tilde?

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2015년 2월 7일
편집: Jan 2015년 2월 7일
There is no way, as far as I know neither officially nor undocumented.
Instead of coding the unwanted outputs by the tilde, using a clear and clean input argument is better in my opinion. It is much better to see the intention of the programmer eplicitly than a smart and fancy way to hide this inside intelligent parsing.
If you see a foreign code, or a code written by your own some years ago, decide what is nicer:
opt.OutputX_wanted = false;
y = myfunc(x, opt);
or
[~, y] = myfunc(x)
In the first case you can imagine, that myfunc can save some time, in the second this is not expected by experienced Matlab programmers. Although if the 2nd method might save some lines of code or some microseconds of run time, the debug time rules.
  댓글 수: 2
Alex R.
Alex R. 2015년 2월 7일
편집: Alex R. 2015년 2월 8일
In my case the issue is not code cleanliness or speed, but memory and complexity. I'm dealing with big data sizes (>32GB matrices) and code which is fairly complex and which should be backwards compatible with other parts of the code that call it using the tilde (~).
Mathworks introduced the tilde ~ but it's crippled, virtually useless, since the following are equivalent:
[~,y]=myfunc(x);
and
[z,y]=myfunc(x);
clear z;
Memory is allocated for z in both cases, so all that tilde ~ does is save me from calling clear z. I can't see any usage for ~ beyond that.
Given Mathworks introduced this code feature, I think they should do it properly and add complete functionality, i.e. ability to detect ~ and its output index. I'll add a feature request, hopefully they'll listen ...
Cheers
Jan
Jan 2015년 2월 8일
I agree, that the ~ method is not really usful. Therefore programmers have to use more efficient ways.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by