Matlab中的元素比较与绘图

Matlab中的元素比较与绘图,matlab,matlab-figure,Matlab,Matlab Figure,我有两个包含数字的文件。一个数字用于计算骨骼的最大压缩,而另一个数字是骨骼上的压缩。如果第二个数字高于最大压缩,我想用红色绘制圆点,如果小于,则应为绿色。 我的问题是,我所有的圆点都显示为红色,尽管大部分应该是绿色的。我试着通过打印出H和C向量来调试它,大约有100个数字应该是红色的,其余的是绿色的。任何帮助或提示都将不胜感激 这是我的密码 p=VarName5; c=VarName7*2.5; %%The compression that is on the bone if p<0.31

我有两个包含数字的文件。一个数字用于计算骨骼的最大压缩,而另一个数字是骨骼上的压缩。如果第二个数字高于最大压缩,我想用红色绘制圆点,如果小于,则应为绿色。
我的问题是,我所有的圆点都显示为红色,尽管大部分应该是绿色的。我试着通过打印出H和C向量来调试它,大约有100个数字应该是红色的,其余的是绿色的。任何帮助或提示都将不胜感激

这是我的密码

p=VarName5;
c=VarName7*2.5; %%The compression that is on the bone
if p<0.317;
  H=10500*p.^1.88; %%Calculate max compression the bone handles
else 
  H=114*p.^1.72; %%Calculate max compression the bone handles
end
if(c < H) %% if the compression on the bone is smaller then max compression
  plot(p,c,'+G') %% plot using green+
  hold on
else
  plot(p,c,'+R')  %if the compression is higher than max compression use red+
end
hold off
p=VarName5;
c=VarName7*2.5;%对骨骼的压迫

如果p可以创建一个逻辑向量,其中大于最大值的所有元素均为1,而其他所有元素均为0:

ind = c > H;
plot(p(ind),c(ind),'+R')
hold on
plot(p(~ind),c(~ind),'+G')
然后可以分别绘制它们

用一些随机数据来说明:

c = repmat([1:6 7:-1:1],1,2);  %// The compression
H = rand(1,numel(c))*8; %// The compression the bone handles (in this case: random)
p = 1:numel(c);

ind = c > H;  %// Index of elements where the bone is compressed more than it handles.
plot(p(ind),c(ind),'+R')
hold on
plot(p(~ind),c(~ind),'+G')


我将让您自己决定如何在代码中实现它。

完美,这正是我想要的。不知道我能用这样的情节。