A = [1 0 0 0 2 0 3 0 0 0 0 4 0 5 ....]
B = [1 1.25 1.5 1.75 2 2.5 3 3.2 3.4 3.6 3.8 4 4.5 5 ....]
Is there a function for this?

 Akzeptierte Antwort

Stephen23
Stephen23 am 17 Nov. 2015
Bearbeitet: Stephen23 am 17 Nov. 2015

0 Stimmen

You could use interp1:
>> A = [1,0,0,0,2,0,3,0,0,0,0,4,0,5];
>> X = find(A);
>> B = interp1(X,A(X),1:numel(A))
B =
1.0000 1.2500 1.5000 1.7500 2.0000 2.5000 3.0000 3.2000 3.4000 3.6000 3.8000 4.0000 4.5000 5.0000

Weitere Antworten (1)

Andrei Bobrov
Andrei Bobrov am 17 Nov. 2015

1 Stimme

A = [1 0 0 0 2 0 3 0 0 0 0 4 0 5];
t = A ~= 0;
x = 1:numel(A);
B = interp1(x(t),A(t),x);

Kategorien

Mehr zu Elementary Math finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by