Rody Oldenhuis
Rody Oldenhuis

Reputation: 38032

Bug in patch() in R2016a?

When I execute the following command on MATLAB R2016a:

patch([0 1 1 0],....
      [0 0 1 1],...
      cat(3, [0.55 0.45 0 0],...
             [0.45 0.35 0 0],...
             [0.25 0.15 0 0]),...
      'facecolor', 'interp');

I get:

Error using patch

Vectors must be the same length.

However, I can execute it perfectly fine in any other version. I tried on R2010a, R2014a and R2017a, all with the same result:

enter image description here

The (relevant) documentation (help patch) states:

patch(X,Y,C) creates one or more filled polygons [...] If C is 1-by-n-by-3, where n is the number of columns of X and Y, then each face j is flat colored by the RGB triplet C(1,j,:).

So clearly, this is a bug in R2016a. But I can't find a bug report about this...Can anyone point me in the right direction?

And what would be the best workaround to achieve the desired effect, version agnostically?

Upvotes: 3

Views: 63

Answers (1)

Lior
Lior

Reputation: 2019

The RGB triplets should be transposed:

patch([0 1 1 0], [0 0 1 1],...
      cat(3, [0.55 0.45 0 0].',...
             [0.45 0.35 0 0].',...  % <- NOTE: transposed
             [0.25 0.15 0 0].'),...
      'facecolor', 'interp');

Upvotes: 2

Related Questions