i want to transform this into a function

1 回表示 (過去 30 日間)
Mahmoud Chawki
Mahmoud Chawki 2021 年 4 月 30 日
編集済み: DGM 2021 年 4 月 30 日
this is the algorith
Q1=q(2);
Q2=q(3)-q(2);
Q3=q(4)-q(3);
Q4=q(5)-q(4);
Q5=q(6)-q(5);
Q6=q(7)-q(6);
Q(n)=q(n+1)-q(n);
how can i plot this into matlab
  1 件のコメント
Mahmoud Chawki
Mahmoud Chawki 2021 年 4 月 30 日
i want to have a Q vector that contains these results.

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

回答 (1 件)

DGM
DGM 2021 年 4 月 30 日
編集済み: DGM 2021 年 4 月 30 日
I don't really see why you need a function if you can just do
Q = [q(2) diff(q(2:end))];
But if you really want one:
You could make an anonymous function
q = randi(9,1,10)
myfunction = @(q) [q(2) diff(q(2:end))];
Q = myfunction(q)
or you could make a regular function
q = randi(9,1,10)
Q = myfunction(q)
function out = myfunction(in)
out = [in(2) diff(in(2:end))];
end
Both of these assume that q is a row vector. If your vector orientation varies, you'll have to deal with that accordingly.

カテゴリ

Help Center および File ExchangeSpectral Measurements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by