stuck on a simple cumsum prob
古いコメントを表示
I have a variable x. I make a variable y. I now need to regenerate my variable xNew from y.
Its very close but not exact. Why not? what I have done wrong?
x = cumsum(randn(1000,1));
y = 0.5.*(x(3:end) - x(1:end-2));
xNew = cumsum(y);
plot(x(3:end)); hold all; plot(xNew);
採用された回答
その他の回答 (1 件)
Thomas
2012 年 5 月 29 日
x = cumsum(randn(1000,1));
%y = (x(2:end) - x(1:end-1));
y=[x(1); (x(2:end) - x(1:end-1))];
xNew = cumsum(y);
plot(x(2:end)); hold all; plot(xNew);
isequal(x,xNew)
3 件のコメント
Oleg Komarov
2012 年 5 月 29 日
This problem is kinda different. There's no linear interpolation here.
Matlab2010
2012 年 5 月 29 日
Thomas
2012 年 5 月 29 日
Hmm. then as oleg says you need, x(1) and x(end) for each value to interpolate..
カテゴリ
ヘルプ センター および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!