How to get dimensions of MATLABArray using MATLABEngine with .NET

조회 수: 3 (최근 30일)
Nolin Borrero Jr
Nolin Borrero Jr 2024년 5월 22일
댓글: Nolin Borrero Jr 2024년 6월 4일
When using a MathWorks.MATLAB.Types.MATLABArray, how do you get the dimensions of the array? I cannot find any properties that expose it.
  댓글 수: 5
Michael VanMeter
Michael VanMeter 2024년 6월 4일
편집: Michael VanMeter 2024년 6월 4일
As you pointed out there are no public members exposed for the information you seek. Why are you trying to operate on the MATLABArray class and not converting to a native .NET type?
using MathWorks.MATLAB.Engine;
using (dynamic matlab = MATLABEngine.StartMATLAB())
{
double[,] results = matlab.magic(5.0);
int rows = results.GetLength(0);
int cols = results.GetLength(1);
}
Nolin Borrero Jr
Nolin Borrero Jr 2024년 6월 4일
My goal is to be able to handle returned values without knowing the type and size ahead of time. It's looking like this just isn't possible though the more I look into it.
For my implementation, I will have a struct returned that could have different fields and values. I wanted to be able to look at the data that is returned to determine how to use it. For the sample you have there, you have to know that you are receiving a 2D double.
Right now, I'm basically going down the route where I have to assume the data returned looks exactly as expected and then just handle exceptions. In older versions of MATLAB COM and Runtime, I could see the size and types of MWArrays and handle them that way. This appears to have been removed.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Deploy to .NET Applications Using MWArray API에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by