필터 지우기
필터 지우기

How to add NaN columns in a vector?

조회 수: 5 (최근 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 CenterFile Exchange에서 Code Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by