我正在创建一个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); %// resultThe 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.
更多推荐
发布评论