Matlab绘制点并显示值 [英] Matlab drawing points and show values
本文介绍了Matlab绘制点并显示值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的情节问题.
在x轴上,值是K,例如从2到12,是离散的. 在y轴上,值是C,例如从1到10,是离散的.
我的功能是分段的:
如果K <2C,则<p;如果K <2C,则为p. 如果K> = 2C,则K + 2C;我想显示(K,C)点的值:
(1,1)显示为1 (1,2)显示为1 (2,1)显示为4 (2,2)显示为2
我该怎么做?
非常感谢,
Casper
解决方案
您可以使用 ndgrid 创建K和C:
[K C] = ndgrid(2:12,1:10);
然后使用逻辑索引来计算各个部分:
z=zeros(11,10);
ind = K>=(2*C);
z(~ind) = K(~ind);
z(ind) = K(ind)+2*C(ind);
然后按照您想要的方式绘制:
surf(C,K,z);
或
image(z);
和其他人......
I have a simple plot question.
On x axis, the values are K, say from 2 to 12, discrete. On y axis, the values are C, say from 1 to 10, discrete.
My function is piecewise:
K if K<2C; K+2C if K>=2C;
I want to show the values at points (K,C):
(1,1) Show as 1 (1,2) Show as 1 (2,1) Show as 4 (2,2) Show as 2 ect.
How would I do that?
Many thanks,
Casper
解决方案
You can use ndgrid to create K and C:
[K C] = ndgrid(2:12,1:10);
then use logical indexing to calculate the separate parts:
z=zeros(11,10);
ind = K>=(2*C);
z(~ind) = K(~ind);
z(ind) = K(ind)+2*C(ind);
then plot any way you want:
surf(C,K,z);
or
image(z);
and others....
这篇关于Matlab绘制点并显示值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文