[英]Matlab plot: auto update corresponding y when x changed
我想用X和Y繪圖,當我更新X的范圍時,矢量大小會改變,所以Y需要再次分配如下:
>> y = sin(x)
如果我不這樣做,我通常得到:
>> plot (x,y)
Error using plot
Vectors must be the same lengths.
所以我想知道,如果有辦法自動完成
你可以使y
成為一個函數(句柄),
y = @(x)sin(x)
plot (x,y(x),x2,y(x2),x3,y(x3),x4,y(x4))
當然,有了這么簡單的功能,你也可以堅持使用sin
,即
plot (x,sin(x),x2,sin(x2),x3,sin(x3),x4,sin(x4))
您可以組合plot
命令以進一步簡化調用:
plotsin = @(x)plot(sin(x));
這樣你就可以打電話了
plotsin(x);
對於任何輸入x
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.