フィルターのクリア

How to add NaN columns in a vector?

7 ビュー (過去 30 日間)
Syed Wafa
Syed Wafa 2017 年 2 月 26 日
編集済み: Roger Stafford 2017 年 2 月 26 日
I have a vector X which is a 1*38 double (x1,x2,x3,x4,x5,....x38). I want to calculate the difference between every adjacent cell (for example, between x3 and x4, x4 and x5 etc.) and if the difference is greater than 0.0002, I want NaN columns to be added between the two adjacent cells, such that the number of columns between adjacent cells will equal the difference divided by 0.0002.

回答 (1 件)

Roger Stafford
Roger Stafford 2017 年 2 月 26 日
編集済み: Roger Stafford 2017 年 2 月 26 日
Let X be your row vector.
p = cumsum([1,1+floor(abs(diff(X))/0.0002)]);
T = NaN(1,p(end));
T(p) = X;
X = T;
(Note: This doesn't reshape X. It extends its length by the insertion of NaNs.)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by