How to access an individual value of MWNumericArray

3 ビュー (過去 30 日間)
yusuf a
yusuf a 2018 年 7 月 19 日
回答済み: Jason Whitfield 2018 年 7 月 19 日
I created a .net assembly for this Code:
function y = makesquare(x)
y = magic(x);
Then I build a .NET application using this code:
// Make .NET Namespaces available to your generated component.
using System;
using MagicSquareComp;
using MathWorks.MATLAB.NET.Arrays;
// Initialize your classes before you use them.
namespace MainApp
{
class Program
{
static void Main(string[] args)
{
MLTestClass obj = null;
MWNumericArray input = null;
MWNumericArray output = null;
MWArray[] result = null;
// Because class instantiation and method invocation make their exceptions at run time,
// you should enclose your code in a try-catch block to handle errors.
try
{
// Instantiate your component class.
obj = new MLTestClass();
// Invoke your component.
input = 5;
result = obj.makesquare(1, input);
// Extract the Magic Square you created from the first index of result
output = (MWNumericArray)result[0];
// print the output.
Console.WriteLine(output);
}
catch
{
throw;
}
}
}
}
How can I access to individual value of MWNumericArray, e.g. I want to display each value in Message Box MsgBox(myIndividualValue);

採用された回答

Jason Whitfield
Jason Whitfield 2018 年 7 月 19 日
Try using the ToArray method. e.g.
double[] values = output.ToArray(MWArrayComponent.Real);
You should then be able to index that array to get the individual values.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDeploy to .NET Applications Using MWArray API についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by