首页 > 解决方案 > How to assign different colors to each data set using plotpv?

问题描述

I am studying neural networks and I need to know if it is possible to show datasets with different colors using the plotpv function.

I was assigned a homework task in which I separated two sets of data with a straight line (both sets are linearly separable by the calculations thrown by a perceptron.) If I'm not wrong, plotpv uses the symbols (+) and (or) by default for P and T (the names of both data sets).

The homework asks us to show each set of similar data with its own color, but I can not find a way to assign a different color to each data. Everything is shown in blue. I have thought about copying the code of the plotpv function and looking at where each element is shown to change the color of one of the two sets.

I guess that it would be useful tell you that I found a similar case related to plotpc, but that case has not provided me with enough information to determine how to do what is requested in the homework. This is the link:

Different color line with plotpc in matlab

I don't have any code to show you. I have few experience in MATLAB. Also, I suppose that the solution would has few lines, rigth?

I would like to get red +'s and blue o's.... (for example)

标签: matlabneural-network

解决方案


就输出样式而言,plotpv它不是很有帮助,因为它不会将句柄返回到绘制的对象。但是,您可以将它们作为相应axes.

以下代码将 s 的MarkerEdgeColor-property设置o为 red 和+black。

% plot data
p = [0 0 1 1; 0 1 0 1];
t = [0 0 0 1];
plotpv(p,t)

% change colors
ax = gca
for i = allchild(ax)'
    switch i.Marker
        case '+'
            i.MarkerEdgeColor = 'k';
        case 'o'
            i.MarkerEdgeColor = 'r';
    end
end

在此处输入图像描述


推荐阅读