Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于距离直线的MATLAB彩色点绘制_Matlab_Scatter Plot_Scatter - Fatal编程技术网

基于距离直线的MATLAB彩色点绘制

基于距离直线的MATLAB彩色点绘制,matlab,scatter-plot,scatter,Matlab,Scatter Plot,Scatter,我在MATLAB中有一组2D中的m点和一组n线。假设n线以n颜色绘制,我需要用最接近的线集的平均颜色绘制每个点。我可以计算点与直线之间的距离,但如何使用散射将点的颜色设置为一个值,该值由点与最接近直线之间的距离加权?该示例应能帮助您: clear all; close all; m = 20; %number of points markerSize = 25; %example points a=rand(2,m); a(:,m-1) = [0;0]; % this point will

我在MATLAB中有一组2D中的
m
点和一组
n
线。假设
n
线以
n
颜色绘制,我需要用最接近的线集的平均颜色绘制每个点。我可以计算点与直线之间的距离,但如何使用
散射
将点的颜色设置为一个值,该值由点与最接近直线之间的距离加权?

该示例应能帮助您:

clear all;
close all;

m = 20; %number of points
markerSize = 25;

%example points
a=rand(2,m);
a(:,m-1) = [0;0]; % this point will be purple
a(:,m-2) = [1;0]; % this point will be blue
a(:,m-3) = [0;1]; % this point will be red

%line x=0 is red
%line y=0 is blue;
f1 =figure(1);
hold on;
for i = 1:m
    pointColor = [1-a(1,i) 0 1-a(2,i)]; % rgb format - calculate distance here
    % [0 0 0] - black , [1 1 1] - white
    % pointColor=(lineColor1*distance1 + lineColor2*distance2+...)/numberOfClosestLines;
    scatter(a(1,i),a(2,i),markerSize, pointColor)
end

这个例子应该能帮助你:

clear all;
close all;

m = 20; %number of points
markerSize = 25;

%example points
a=rand(2,m);
a(:,m-1) = [0;0]; % this point will be purple
a(:,m-2) = [1;0]; % this point will be blue
a(:,m-3) = [0;1]; % this point will be red

%line x=0 is red
%line y=0 is blue;
f1 =figure(1);
hold on;
for i = 1:m
    pointColor = [1-a(1,i) 0 1-a(2,i)]; % rgb format - calculate distance here
    % [0 0 0] - black , [1 1 1] - white
    % pointColor=(lineColor1*distance1 + lineColor2*distance2+...)/numberOfClosestLines;
    scatter(a(1,i),a(2,i),markerSize, pointColor)
end

为每条线指定一个整数标志,然后将其用作
C
scatter
索引。这不会根据与线的距离绘制点的颜色,是否应该使用与线的距离来确定颜色?我还想提到点和线的数量是不同的。你能发布一个吗?根据你已经计算过的最近的线,给每一行一个整数标志,然后用它作为
C
分散的索引。例如,所有最接近底线的点都会得到标志
1
,所有最接近第二行的点都会得到标志
2
等。该列可以用作
C
输入,以分散点来给点上色。(抱歉,我错过了第一条评论中的标志所基于的内容)为每一行指定一个整数标志,然后将其用作
C
散点的索引。这不会使用基于线距离的颜色绘制点,难道不应该使用线距离来确定颜色吗?我还想提到点和线的数量是不同的。你能发布一个吗?根据你已经计算过的最近的线,给每一行一个整数标志,然后用它作为
C
分散的索引。例如,所有最接近底线的点都会得到标志
1
,所有最接近第二行的点都会得到标志
2
等。该列可以用作
C
输入,以分散点来给点上色。(抱歉,我在第一条评论中遗漏了国旗的依据)