i need your help with vector creation from original vector

1 回表示 (過去 30 日間)
Mustafa Ahmed
Mustafa Ahmed 2021 年 5 月 2 日
コメント済み: Image Analyst 2021 年 5 月 2 日
please help
i have a vector called x =1:20
find the vector of 𝑑𝑥 = {𝑥_𝑖 + 1 - 𝑥_i}
for 𝑖 = {1, 2,. . . , 𝑁 - 1}

回答 (2 件)

Ahmet Parker
Ahmet Parker 2021 年 5 月 2 日
Hard way
do a for loop
sizex=size(x);
for i=1:sizex(1,2)-1
dx(i)=x(i+1)-x(i);
end
  1 件のコメント
Mustafa Ahmed
Mustafa Ahmed 2021 年 5 月 2 日
that worked very well thanx alot
x=[17 8 12 15 6 11 9 18 16 10 13 19];
i=1:11;
sizex=size(x);
for i=1:sizex(1,2)-1
dx(i)=x(i+1)-x(i);
end
disp(dx)

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


Image Analyst
Image Analyst 2021 年 5 月 2 日
  1 件のコメント
Image Analyst
Image Analyst 2021 年 5 月 2 日
%--------------------------------------
% Method 1 : for loop
x = [17 8 12 15 6 11 9 18 16 10 13 19];
i = 1 : 11;
sizex = size(x);
for i = 1 : sizex(1,2)-1
dx(i)=x(i+1)-x(i);
end
fprintf('Results for for loop:\n');
disp(dx)
%--------------------------------------
% Method 2 : diff() function
fprintf('Results for diff():\n');
disp(diff(x))
fprintf('Done running %s.m ...\n', mfilename);
Results for for loop:
-9 4 3 -9 5 -2 9 -2 -6 3 6
Results for diff():
-9 4 3 -9 5 -2 9 -2 -6 3 6

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by