I have a position expression and a velocity expression. I want to output a 2 column matrix with the data from t=0 to t=15. My t variable is t = linspace(0,15,100)' . Here is my code :
--------------------------
function [ x,xdot ] = finalproject( t )
% x represents position and xdot represents velocity
x = exp(-t./2).*(20.*cos(1.3229.*t)+22.6775.*sin(1.3229.*t));
xdot = exp(-t./2).*(20.*(-1./2.*cos(1.3229.*t) - 1.3229.*sin(1.3229.*t)) + 22.6775.*(-1./2.*sin(1.3229.*t) + 1.3229.*cos(1.3229.*t)));
end
------------------
In the Command Window, I know i need to have [.....] = finalproject(t) I can't seem to get it to work after trying various combinations of function output arguments and variables in the command window bracket.

 採用された回答

Geoff Hayes
Geoff Hayes 2016 年 10 月 22 日

1 投票

Zachary - your function is outputting two columns of 100 elements each (given your example t). So you would call this function (from the command line) as
>> [x,xdot] = finalproject(t);
You can then combine them into a two column matrix as
>> data = [x xdot];
If you want your function to output a two column matrix, then you will need to change its signature and body to
function [ result ] = finalproject( t )
% x represents position and xdot represents velocity
x = exp(-t./2).*(20.*cos(1.3229.*t)+22.6775.*sin(1.3229.*t));
xdot = exp(-t./2).*(20.*(-1./2.*cos(1.3229.*t) - 1.3229.*sin(1.3229.*t)) + 22.6775.*(-1./2.*sin(1.3229.*t) + 1.3229.*cos(1.3229.*t)));
result = [x xdot];
end

1 件のコメント

Zachary Hauck
Zachary Hauck 2016 年 10 月 22 日
A quick simple answer that works, thanks Geoff!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeIntroduction to Installation and Licensing についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by