Matlab Exception while using C#
2 views (last 30 days)
Show older comments
Hello,
I've made a dll version of a clustering algorithm implemented in matlab http://www.psi.toronto.edu/affinitypropagation/software/apclusterSparse.m
Also, I've downloaded an working sample of the input data and I'm reading it and also converting it to a Matlab known data type.
The data sample can be found here: http://www.psi.toronto.edu/affinitypropagation/webapp/ --- It's the Toy Problem
However, when running the algorithm I get the following error:
... MWMCR::EvaluateFunction error ... Dimensions of matrices being concatenated are not consistent. Error in => apclusterSparse.m at line 178.
Here is my code: (sorry?)
public static double[,] ReadSimilarities() { string line; string[] splittedLine; System.IO.StreamReader file = new System.IO.StreamReader("similarities.txt");
List<List<string>> values = new List<List<string>>();
List<string> lineValues;
while ((line = file.ReadLine()) != null) { splittedLine = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); lineValues = new List<string>(splittedLine.Count());
for (int i = 0; i < splittedLine.Count(); i++) { lineValues.Add(splittedLine[i]); }
values.Add(lineValues); }
file.Close();
double[,] result = new double[values.Count, 3];
for (int i = 0; i < values.Count; i++) { result[i, 0] = Convert.ToDouble(values.ElementAt(i).ElementAt(0)); result[i, 1] = Convert.ToDouble(values.ElementAt(i).ElementAt(1)); result[i, 2] = Convert.ToDouble(values.ElementAt(i).ElementAt(2)); } return result; }
public static double[] ReadPreferences() { string line; System.IO.StreamReader file = new System.IO.StreamReader("preferences.txt"); List<string> values = new List<string>();
while ((line = file.ReadLine()) != null) { values.Add(line); }
double[] result = new double[values.Count]; for (int i = 0; i < values.Count; i++) { result[i] = Convert.ToDouble(values.ElementAt(i)); }
return result; }
public ActionResult Index() { ApClusterSparse apClusterSparse = new ApClusterSparse();
double[,] similarities = ReadSimilarities(); double[] preferences = ReadPreferences();
MWNumericArray matLabSimiliaritiesArray = new MWNumericArray(similarities); MWNumericArray matLabPreferencesArray = new MWNumericArray(preferences); MWArray argsOut;
try { argsOut = apClusterSparse.apclusterSparse(matLabSimiliaritiesArray, matLabPreferencesArray); } catch (Exception e) {
}
return View(); }
0 Comments
Answers (0)
See Also
Categories
Find more on Deploy to .NET Applications Using MWArray API in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!