0

Let's say W = [1 3 5; 2 1 5; 6 9 1] and K = [0.2, 0.5, 0.3] How can I plot all elements in k with the same color exept those elements that have at least one element in W grather than 6? I need that K(3)will be plotted with another color respect K(1) and K(2)

gmeroni
  • 571
  • 4
  • 16

2 Answers2

1

You need to plot as two series. You can use the any/all functions to check the logical condition columnwise: since you want to check rowwise, we need to use the transpose of W.

exceptions = find(any(W' > 6));
normals = find(all(W' <= 6));
plot(exceptions, K(exceptions), 'b.')
hold on
plot(normals, K(normals), 'g.')
Max
  • 2,121
  • 3
  • 16
  • 20
0

If you plot point-by-point you can change the color correspondingly, for example something like this:

for i = 1:size(W,2)
    if find(W>6)~=0
        plot(i,K(i),'xb');hold on
    else
        plot(i,K(i),'xr');hold on
    end
end

Since the information you gave is not enough, the code above needs to be modified according to W and K,....

NKN
  • 6,482
  • 6
  • 36
  • 55
  • You should avoid using 'i' as a variable name in Matlab: http://stackoverflow.com/questions/14790740/using-i-and-j-as-variables-in-matlab – Max Feb 20 '14 at 09:48
  • @Max you are right, but for me it is an old habit that I am used to ;) – NKN Feb 20 '14 at 10:23