Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.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_Colors_Conditional_Scatter Plot - Fatal编程技术网

Matlab中带条件的散点图

Matlab中带条件的散点图,matlab,colors,conditional,scatter-plot,Matlab,Colors,Conditional,Scatter Plot,我有一组粒子数据 第1列是粒子的电荷,第2列是x坐标,第3列是y坐标 我已经重命名了第1列c_粒子、第2列x_粒子和第3列y_粒子 我需要做x和y的散点图,但是当电荷为正时,标记必须是红色,当电荷为负时,标记必须是蓝色 到目前为止我有 if c_particles < 0 scatter(x_particles,y_particles,5,[0 0 1], 'filled') else scatter(x_particles,y_particles,5,[1 0 0], 'filled')

我有一组粒子数据

第1列是粒子的电荷,第2列是x坐标,第3列是y坐标

我已经重命名了第1列c_粒子、第2列x_粒子和第3列y_粒子

我需要做x和y的散点图,但是当电荷为正时,标记必须是红色,当电荷为负时,标记必须是蓝色

到目前为止我有

if c_particles < 0
scatter(x_particles,y_particles,5,[0 0 1], 'filled')
else
scatter(x_particles,y_particles,5,[1 0 0], 'filled')
end
如果c_粒子<0
散射(x_粒子,y_粒子,5,[0 0 1],“填充”)
其他的
散射(x_粒子,y_粒子,5,[10],“填充”)
结束

这就产生了情节,但标记都是红色的

你的第一句话没有达到你想象的效果:

c_particles < 0
i_negative = (c_particles < 0);       % logical index of negative particles
i_positive = ~i_negative;             % invert to get positive particles
x_negative = x_particles(i_negative); % select x-coords of negative particles
x_positive = x_particles(i_positive); % select x-coords of positive particles
y_negative = y_particles(i_negative);
y_positive = y_particles(i_positive);

scatter(x_negative, y_negative, 5, [0 0 1], 'filled');
hold on; % do the next plot overlaid on the current plot
scatter(x_positive, y_positive, 5, [1 0 0], 'filled');