213 views (last 30 days)

Hi, I have a matrix, M which is 10*2000 double (10 rows of signals and each signal contains 2000 variables). I want to shift each of the signal in this matrix to the right by say 1. I have a code (below) that can shift a single signal (that is if M contains a single signal, 1*2000). How do I modify this to shift each signal in M at the same time?

The code code for shifting a single signal is:

p = M;

Shift = 1;

Shifted_M = circshift(p,Shift);

In summary, I want a code that can shift each independent row signal in a matrix and output the shifted matrix as Shifted_M. After that I would like to plot this shifted matrix with the original data to visualize it.

Thanks

Adam Danz
on 18 Jun 2020

If you'd like to circularly shift the data "A" by "K" positions along the "dim" dimension,

So, you'll need to specify the dimension.

Adam Danz
on 19 Jun 2020

"The code is just adding 1 to all the variables and not shifting their positions."

That's incorrect. When you plot two variable using plot(r,q) the x-coordinates are defined by r. To shift them one unit to the right, you would add 1 to the x-coordinates. plot(r+1,q).

It makes sense, right? If r=3 and you want to shift it by 1 unit to the right, then r0=3+1.

Here's an example.

r = 1:10;

q = sort(randn(1,10));

cla()

plot(r, q, 'r-o')

hold on

plot(r+1, q, 'b-o')

It's still not clear how your matrix values should be visualized. For example, for matrix M,

m = [ 2 4 1 0 8

8 2 1 9 0

1 9 2 0 3];

if the x coordinates are x=[1 2 3 4 5] and the y coordinates are y=[1 2 3], then at coordinate (1,1) the value of m is 2. Does that mean you want a 3D plot were m contains the z-values?

Adam Danz
on 19 Jun 2020

Opportunities for recent engineering grads.

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

Start Hunting!
## 1 Comment

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/550752-shifting-signals-to-the-right#comment_903870

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/550752-shifting-signals-to-the-right#comment_903870

Sign in to comment.