簡體   English   中英

在Matlab中繪制變量受約束的圖

[英]plot in matlab with constraints in the variables

我想繪制一個表格的函數

f(p,q)=0

0 < p < 1, 0 < q < 1-p 我用ezplot

ezplot('f(p,q)',[0,1]) 

是我能做的。 但看起來丑陋,因為該函數是公在三角形區域僅限定0 < p < 1, 0 < q < 1-p 因此,我認為,在該區域之外,它僅繪制了函數的實部/虛部,因此較難看。 但我只想在三角形區域0 < p < 1, 0 < q < 1-p繪制。

有人可以幫忙嗎?

這是一個示例,說明如何提取要繪制的值。 這絕不是您要做的事情的復制粘貼答案。

p = -1:.1:2; % Just giving p some random values so that we can pull 0 < p < 1 from it.
ind = intersect(find(p>0), find(p<1)); % This returns the intersection of the two sets from p.  Not really the best way, but it's a concise one-liner.

% Now to pull the values from p.
p_values = p(ind); % That simple!  This is because ind has the actual indexes where p < 1 and p > 0.

老實說,這可能不是從p中獲取信息的最佳方法,但這只是在我喝咖啡之前浮現在腦海的東西。

至於獲取q的信息,您可以遵循類似的方式,只是確保您在為其設置的約束之內。

請記住,在進行繪圖時,您需要具有相同長度的向量,但是如果您對p_values進行索引以獲得q_values那么您應該在那里q_values很好。

希望這能使您有所起點並走上正確的道路。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM