About Matlab。

2008-02-21 9:45 am
I have a vector function in matlab: function cubic(t);
cubic = zeros(2,1); % a column vector x = 2t^2 +1; y = t^3; cubic(1) = x; cubic(2) = y; I have two questions: (1) I have an array T=[0:0.01:1] , I want to obtain a matrix of X=cubic(T) and I always have error about this syntax. How could I obtain X? (2) In fact, I initially want to plot x against y, in the range t=0..1 , how could I do that? Thanks in advance.
更新1:

Hello, (1) I believe that there is a trick other than using loop, otherwise MATLAB is useless!! e.g. Y=sin(T); Y is then an array without any looping statement.

更新2:

(2) If the code is wrong, how could I use [plot] ? Could someone kindly show me the [correct and exact codes] to me? Thanks a lot.

回答 (1)

2008-02-23 11:13 am
✔ 最佳答案
a.)Syntax error.
because input to cubic should be scalar, but not a vector

Solution:
Use a for-loop to input:
for i from 1 to 100
x(i) = cubic(T(i));
end

b.) use the function plot

2008-02-26 22:52:43 補充:
Hi,
Instead of the loop, I think it's the problem in writing the function.

say, we should write:
y=t.^3

If you input a vector T, then the output Y will be also a vector with same dimension.

The dot means entry-by-entry.

Hope helps.

Po
參考: me


收錄日期: 2021-04-23 20:04:17
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20080221000051KK00223

檢視 Wayback Machine 備份