Lay one vector onto another
1 回表示 (過去 30 日間)
古いコメントを表示
Say you had two row vector:
filter = [0 0 0 0 0 0 0 0 0 0 ];
values = [1 2 1];
And the goal is to "lay the vector values onto the vector filter" like this:
new_filter = [0 0 1 2 1 0 0 0 0 0];
Here being done onward from index 3, or any other index.
How would that work?
2 件のコメント
Stephen23
2018 年 5 月 11 日
"Here being done onward from index 3, or any other index. How would that work?"
You said it yourself: using indexing. What have you tried so far?
回答 (1 件)
Cathal Cunningham
2018 年 5 月 11 日
One method would be a for loop
filter = [0 0 0 0 0 0 0 0 0 0 ];
values = [1 2 1];
startIdx = 3;
for i = startIdx:length(filter)-startIdx+1
new_filter = filter;
new_filter(i:i+length(values)-1) = values
end
Or you could try circshift
filter = [0 0 0 0 0 0 0 0 0 0];
values = [1 2 1];
startIdx = 3;
new_filter = filter;
new_filter(startIdx:startIdx+length(values)-1) = values
for i = 1:length(filter)
new_filter = circshift(new_filter,1)
end
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!