expanding matrix with linear line between new samples

조회 수: 1 (최근 30일)
Kamyar Mazarei
Kamyar Mazarei 2021년 5월 8일
편집: Matt J 2021년 5월 9일
hi
lets say i have a 1x20 matrix called A which are samples of a plot
i want to expand A to be 1x50
when i try to make it lets call is matrix B, the samples in the middle are zero and i just want the previous and the next sample to connect (avrage/avrages)
lets say A=[1 2 3 4 5 6 ...
i want a B=[1 0 2 0 3 0 4 ... ===> B=[1 1.5 2 2.5 3 3.5 4]
BUT heres the thing theyre not equally distributed
B=[1 0 0 0 2 0 0 3 ... ===> B=[1 1.25 1.5 1.75 2 2.33 2.66 3 ...
what im asking is how to expand my matrix to be linearly connected between samples
thank you
and sorry for bad english
  댓글 수: 1
Turlough Hughes
Turlough Hughes 2021년 5월 8일
How do you define the number 0's between nonzero values in B?

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2021년 5월 9일
편집: Matt J 2021년 5월 9일
B=[1 0 0 0 2 0 0 3];
x=find(B~=0);
xq=1:numel(B);
B=interp1(x,B(x),xq)
B = 1×8
1.0000 1.2500 1.5000 1.7500 2.0000 2.3333 2.6667 3.0000

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by