Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
matlab: ベクトル P があります。値 P(k+1) - P(k) を新しいベクトル M に格納したいです。for ループで実行できますが、より効率的なものはありますか (私が持っている巨大なベクトル)。
シンプルなソリューション
差 = V(2:n) - V(1:n-1) ここで、n はベクトル V のサイズです。
n = サイズ (V,1);
マーシンが言ったように、を使用してdiffください。1D ベクトルの場合、diff(a). ディム 1 に沿った差分については、diff(a,[],1). 寸法 2 に沿って、 を使用しますdiff(a,[],2)。
diff
diff(a)
diff(a,[],1)
diff(a,[],2)