Question

I've made a dll version of a clustering algorithm implemented in matlab

Also, I've downloaded an working sample of the input data (I'm using the Toy Problem data) and I'm reading it and also converting it to a Matlab known data type.

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("C:\\Code\\FCT\\Thesis\\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("C:\\Code\\FCT\\Thesis\\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();
    }

Thanks.

Was it helpful?

Solution 2

The problem was with the argument P must not be an array (as is on the website input) but instead, a scalar.

OTHER TIPS

From a quick look at line 178 of your code, it looks like you're concatenating an Nx2 array with p, and then concatenating that with s, where sometimes N is defined as length(p), sometimes as size(s,1) and sometimes as something called tmp.

I'm not going to debug this, but I would suggest that to do so you should modify your code so that before line 178 it displays, or somehow outputs, the values of N, p, s and tmp. This will give you an idea of why they can't be concatenated - I'm guessing that they have different dimensions.

I'd also suggest:

  1. Stop using length, and use either numel or size consistently. length gives you the same answer if its input is 10x1 or 1x10, and is not the right thing to use to check the dimensions of an array before concatenating.
  2. Stop putting multiple statements on a single line, especially complete if statements. If there's an error, you don't know which statement caused it.
  3. Improve your variable naming. It's not surprising this is tough to debug when you have variables called A, a, s, ss, as, r, R, rp, p, E, e, ee, idx, ind1, ind1s, ind1e, ind2s, ind2e and tmpidx. It makes my head hurt to read through it.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top