Laden...

Matlab Funktion mittels Feval-Methode im C# aufrufen

Erstellt von neuling86 vor 7 Jahren Letzter Beitrag vor 7 Jahren 1.724 Views
N
neuling86 Themenstarter:in
1 Beiträge seit 2017
vor 7 Jahren
Matlab Funktion mittels Feval-Methode im C# aufrufen

Hallo,

Ich bin absoluter Neuling und bitte hiermit um Verständnis. Ich würde gerne meine Matlab Funktion hier im c# öffnen und der Funktion eine .txt als Übergabeparameter / argument übergeben. Danach soll c# die Matlab Funktion ausführen und mir die Diagramme anzeigen. Nur bekomme ich folgenden Fehler im c#:

Fehlermeldung:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: Error using fileread (line 15)
Filename must be a string.

((Meine Matlab Funktion erstellt Diagramme abhängig vom Input.))

using System;
using System.Collections.Generic;
using System.Text;
//using MathWorks.MATLAB.NET.Arrays;
//using MathWorks.MATLAB.NET.Utility;
//using DotNetProject;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create the MATLAB instance 
            MLApp.MLApp matlab = new MLApp.MLApp();
              // Change to the directory where the function is located 
              matlab.Execute(@"cd C:\Users\z003dukj\Documents\MATLAB\test_2");
              string[] input = System.IO.File.ReadAllLines(@"C:\Users\z003dukj\Documents\MATLAB\aaaa.txt");
              // Define the output 
              object result = null;
              //object  result = "";
              // Call the MATLAB function myfunc
              //matlab.Feval("test_2",0,input);
              matlab.Feval("test_2", 0, out result, input);
              // Display result 
              object[] res = result as object[];
              Console.WriteLine(res[0]);
              Console.WriteLine(res[1]);
              Console.ReadLine();
          }
      }
  } 

Meine Matlab .txt -Datei:

\*******************Cutoff Lines1****************
-100	100
-200	200
\******************* Diagram Options****************
rainflow=1
woehler=0
number_of_plots=4
color=red
linewidth=12
header=Number of cycles
xlabel= RPM
ylabel= Amount
cutoffvalue=53
equivcycles=1e6
equivstress=40
wsectionslope=3 3 3
ordinatelogarithmic=false
wsectionstart=1000 5000000 3000000
wsectionsend=5000000 1000000000 30000000
wsectionlinestyle=cont dashed cont
wsectionstartstress=58.02349610358 58.02349610358 130
\******************* Diagram Limits****************
xmin xmax ymin ymax zmin zmax
1	111	1111111	1	1	11
\*******************Input Data****************
-220.8	228	50045
-222	201.6	50045
-219.6	19.2	200176
-168	19.2	100088
\******************* Diagram Options2****************
number_of_plots=4
wsectionstart=1000 5000000 3000000
\******************* Diagram Limits2****************
xmin xmax ymin ymax zmin zmax
0	0	100000	1	1	1100000
\*******************Input Data2****************
106.62	1
106.62	50045
18.5181	12260785
\******************* Diagram Options3****************
number_of_plots=23655888855665
\******************* Diagram Limits3****************
xmin xmax ymin ymax zmin zmax
0	0	100000	1	1	1100000
\*******************Input Data4****************
-220.8	228	50045
-222	201.6	50045
-220.2	198	200176
-224.4	196.8	200176
-220.8	192	200176
-221.4	190.8	50044
-226.2	176.4	200176
-199.2	156	50044
-201.6	153.6	50045
-219	147.6	50044
-252.6	133.2	50044
-210	129.6	200176
-250.8	127.2	50044
-201	126	50044
-229.2	124.8	50044
-183	123.6	200176
-168	122.4	200176

Als Attachement: Matlab Files.
Danke im Voraus.
lg Philipp

D
985 Beiträge seit 2014
vor 7 Jahren

Ok, du übergibst mit input den Inhalt einer Datei an deine Funktion. Deine Funktion erwartet aber den Dateinamen, weil der Inhalt mit fileread gelesen werden soll.