.NET method with "out" keyword as an input

Hello!
I've run into a tricky situation when trying to work with a .NET library inside MATLAB. Normally, it appears that when a .NET method has a parameter with the out keyword, MATLAB makes it a parameter that is returned instead.
However, I have run into an unusual scenario where a function requires me to input a value for a parameter with the out keyword. I cannot find a public repository for the library in question; However, I've included below an example of how the .NET function in question, ZernikeLSF, is called in a C# script:
After going through the MATLAB documentation on its .NET integration, I have been unable to find a way to input a value for this parameter, zernike_order -- I can only seem to have it be returned. Is there a method of inputting a value here with MATLAB? If not, are there any good workarounds?

댓글 수: 1

Image Analyst
Image Analyst 2024년 8월 23일
How are you calling this function in your MATLAB code?

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

 채택된 답변

Walter Roberson
Walter Roberson 2024년 8월 23일
편집: Walter Roberson 2024년 8월 23일

0 개 추천

C# apparently makes it illegal to read from an "out" parameter before writing to it; https://stackoverflow.com/questions/7716641/using-the-out-keyword-in-c-sharp
If the statements in the above post are correct, then it is not possible to use an "out" parameter to pass in a value.
Although it is legal to pass in an initialized value, the receiving routine cannot read from that value before writing to the variable.
So... the situation you describe apparently cannot occur.

댓글 수: 2

JMB
JMB 2024년 8월 23일
Well... this certainly complicates things for me. The library I am using definitely states that you input a parameter there, and the C code it is based on does something pretty similar. If C# makes it illegal to read from an "out" parameter, then something wacky is happening. I'll reach out to the person who wrote the library in question to get more information.
I appreciate your quick response! This was extremely helpful.
For two-way communication, you would use a ref variable instead of an out variable.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

릴리스

R2024a

태그

질문:

JMB
2024년 8월 22일

댓글:

2024년 8월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by