MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   如何在MATLAB中对图形的因变量执行语句? (https://www.labfans.com/bbs/showthread.php?t=24188)

poster 2019-12-10 20:48

如何在MATLAB中对图形的因变量执行语句?
 
我想知道如何从间隔中获取特定数字以对其进行测试,然后能够在一个图形下构建不同的函数。例如(在本例中为'x'变量),

x 0:.5:5; Ids=ones(x); figure;hold on; for n = 1:5 if(x < 3.0) %problem here Ids(n) = plot(x,x.^x); else if (x > 4.0) %and here Ids(n) = plot(x,-x.^x); end end end 编辑

我真正想在MATLAB中执行的操作是能够执行以下分段功能:

y(x) = { 0 (t - 5) < 0 { (t - 5)*(t - x) x < (t - 5) { (t + x^2) x >= (t - 5) 我似乎不了解如何绘制此函数的图形,因为x = 0:.5:10和t = 0:.1:10 。我知道如何在没有t情况下执行此操作,但是当包含t且与x相比具有不同的间隔时,我会迷路。



[B]回答:[/B]

从代码中还不清楚您要做什么,但是您似乎想创建并绘制具有以下形式的函数f(x) :

f(x) = [ x for 3 4; %# Get a logical index of points greater then 4 y(index) = -x(index).^x(index); %# Change the indexed points plot(x,y); %# Plot y versus x

[url=https://stackoverflow.com/questions/4357995]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 14:17

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.