How to use circshift in Simulink?
3 ビュー (過去 30 日間)
古いコメントを表示
I have a vector signal in Simulink that I want to transform so that each value is replaced by the average of that value and the subsequent value. My first idea was using a MATLAB function block with the following code:
function y = fcn(u)
y = (u+circshift(u,1))/2;
However, this somehow changes the vector to a matrix and leads to an error message:

I don't fully understand this behavior, but it is probably caused by reasons described in the answers to a previous question:
Are there other ways to perform this function using standard Simulink blocks?
3 件のコメント
Walter Roberson
2025 年 4 月 3 日
The first thing I would wonder is whether u is a row vector or column vector; the distinction would make a difference to the circshift() call.
採用された回答
Fangjun Jiang
2025 年 4 月 3 日
It is not really a matrix. I suggest debugging the MATLAB Function first. Provide a Constant vector input, e.g. (1:5), observe the output. Is that what you are expecting?
The error was caused by something else. There is no input data thus no dimension info. Look at the last error message and specify the dimension of the input signal of that Gain block.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!