private void button2_Click(object sender, EventArgs e)
{
IntPtr engine;
engine = matlabClass.engOpen(null);
MWArray []Y=new MWArray[120000];
MWNumericArray plotValue = new MWNumericArray(MWArrayComplexity.Real, 1, 120000);
int k;
double[] m = new double[120000];
object[]n=new object[120000];
for (k = 0; k < 120000; k++)
{
n[k] = dataGridView1.Rows[k].Cells[0].Value;
m[k] = double.Parse(n[k].ToString());
}
for (k = 1; k < 120000; k++)
{
plotValue[1,k+1] = m[k];
}
matlabClass.engSetVisible(engine, false);
matlabClass.engEvalString(engine,"X=1:120000;Y=1:120000;plot(X,Y)");
matlabClass.engClose(engine);
}
最近用c#写调用matlab的plot函数画图,我是用的visualstudio2010和matlab2017a,遇到一个很久没有解决的问题。
```未处理 System.TypeInitializationException
HResult=-2146233036
Message=“MathWorks.MATLAB.NET.Arrays.MWNumericArray”的类型初始值设定项引发异常。
Source=MWArray
TypeName=MathWorks.MATLAB.NET.Arrays.MWNumericArray
StackTrace:
在 MathWorks.MATLAB.NET.Arrays.MWNumericArray..ctor(MWArrayComplexity complexity, Int32[] dimensions)
在 转子系统故障诊断.Form1.button2_Click(Object sender, EventArgs e) 位置 F:\转子系统故障诊断\转子系统故障诊断\Form1.cs:行号 134
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 转子系统故障诊断.Program.Main() 位置 F:\转子系统故障诊断\转子系统故障诊断\Program.cs:行号 18
InnerException: System.TypeInitializationException
HResult=-2146233036
Message=“MathWorks.MATLAB.NET.Arrays.MWArray”的类型初始值设定项引发异常。
Source=MWArray
TypeName=MathWorks.MATLAB.NET.Arrays.MWArray
StackTrace:
在 MathWorks.MATLAB.NET.Arrays.MWNumericArray.get__Inf()
在 MathWorks.MATLAB.NET.Arrays.MWNumericArray..cctor()
InnerException: System.TypeInitializationException
HResult=-2146233036
Message=“MathWorks.MATLAB.NET.Utility.MWMCR”的类型初始值设定项引发异常。
Source=MWArray
TypeName=MathWorks.MATLAB.NET.Utility.MWMCR
StackTrace:
在 MathWorks.MATLAB.NET.Arrays.MWArray..cctor()
InnerException:
HResult=-2146233088
Message=Trouble initializing libraries required by .NET Assembly.
Source=MWArray
StackTrace:
在 MathWorks.MATLAB.NET.Utility.MWMCR..cctor()
InnerException:
环境变量改过了,MCR也卸了装了好几次,目标平台是64位的,应该也没有问题,真不知道问题在哪里,感觉自己都要哭了。![图片说明](https://img-ask.csdn.net/upload/201907/27/1564207055_428476.png)![图片说明](https://img-ask.csdn.net/upload/201907/27/1564207065_980095.png)
数据是复制到dataGridview然后从里面获取的