在MATLAB中将多个点(数据集)转换为函数?(Multiple points (data set) into function in MATLAB?)

编程入门 行业动态 更新时间:2024-10-23 17:23:04
在MATLAB中将多个点(数据集)转换为函数?(Multiple points (data set) into function in MATLAB?)

我正在创建一个1x5双( x = 1:.5:3 ),并希望评估我正在创建的函数中的所有值( f = @(x) 3+2*x + 3*x^2 )

是否也可以将其存储到单列矩阵中? 我希望用不同的x值进行相同的处理,例如( x = 1:1:3 )并比较值。

I am creating a 1x5 double (x = 1:.5:3), and wish to evaluate all of the values in a function that I'm creating (f = @(x) 3+2*x + 3*x^2)

Is it also possible to store this into single column matrix? I wish to do this same process with different x values, say (x = 1:1:3) and compare values.

最满意答案

x = 1:.5:3; f = @(x) 3+2.*x + 3*x.^2; mat(:,1) = f(x); %// result

语法variablename(:,1)允许您将事物存储为列矩阵。 注意函数中的.* ,因为你想要元素地应用这个操作而不是整个矩阵。 如果要存储更多列,只需将1更改为2 ,依此类推。

x = 1:.5:3; f = @(x) 3+2.*x + 3*x.^2; mat(:,1) = f(x); %// result

The syntax variablename(:,1) allows you to store things as a column matrix. Note the .* in the function, since you want to apply this operation elementwise and not as a whole matrix. If you want to store more columns, simply change the 1 to 2 and so forth.

更多推荐

本文发布于:2023-08-05 17:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1437458.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   转换为   中将   函数   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!