How make code has 2 vectors as input and make loop than find output as vector

Hi everyone.
I need know how I can make code I can put two vectors and use them in loop to find another vector as output.
So, for make clear. I have two vectors one of them is time (s), and another one is v ( ft/s ). I want make loop to find acceleration = (V1-V0)/(t1-t0).
Thank you

 採用された回答

Raj
Raj 2019 年 6 月 7 日
編集済み: Raj 2019 年 6 月 7 日
v=rand(10,1);
t=[0:0.1:0.9]';
a=zeros(numel(v),1);
for ii=2:numel(v)
a(ii,1)=(v(ii)-v(ii-1))/(t(ii)-t(ii-1));
end
disp('Acceleration:')
a

5 件のコメント

Murad Alzahrani
Murad Alzahrani 2019 年 6 月 7 日
Thank you. I my v vector is v=[ 0,44,67,34] how I can put this vector?
madhan ravi
madhan ravi 2019 年 6 月 7 日
Isn’t this homework?
Murad Alzahrani
Murad Alzahrani 2019 年 6 月 7 日
No, because I had problem about how make loop with vectors. I know now how you made this. Thank you so much. Now I can finish my work.?? However, I have last question about this line ii=2:numel(v) why you put just v not t ?
Raj
Raj 2019 年 6 月 7 日
Because both are supposed to have same number of elements. So you can use either of them here.
In you case you have mentioned v=[ 0,44,67,34] so t=0:dt:Tf where dt is your sampling time and Tf is your end time. Everything else remains the same.
Murad Alzahrani
Murad Alzahrani 2019 年 6 月 7 日
Thanks

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by