我这里是在.NET winform中写的,主函数代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;
using airPLS;
using System.IO;
using System.Diagnostics;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double[] p1array;
private void Form1_Load(object sender, EventArgs e)
{
#region airplas
string ExcelName = @" C:\Users\yxz\Desktop\p1.txt";
FileStream fs = new FileStream(ExcelName, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs, System.Text.Encoding.UTF8);
string p1data = sr.ReadLine();
string[] strsplit = p1data.Split('\t');
p1array = new double[strsplit.Length];
for (int i = 0; i < strsplit.Length; i++)
{
if (double.TryParse(strsplit[i], out double num))
p1array[i] = num;
}
airPLS airplaobject = new airPLS(10e4, 0, 0.05, 0.05, 20);
airplaobject.airPLSMethod(ref p1array, out double[,] Xc);
#endregion
}
}
在项目解决方案里添加airPLS.cs文件,从MATLAB代码翻译过来,也是花了很多时间,可以从这里下载airPLS,看完这里我建议你通过我的另一篇博客Math.NET进行改写,能够非常大的提高性能。