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일
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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

질문:

2016년 10월 22일

댓글:

2016년 10월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by