Storing a Square Wave in an array that is more than just one row

2 次查看(过去 30 天)
I am trying to store a square wave in an array, but I keep having issues with the sizing. The square wave array that I have is 1 x a user input width(W) and the other array is a user input height(H) x a user input width(W). I was looking to see if there was any way I could use the repmat()/repelem() but had no such luck.
t = 1:1:W
image = (255*square(t.*2.*pi/P));
temp = zeros(W, H);
for x = 1:1:H
% error here
temp(:,x) = image;
%
end
Can anyone tell me where I went wrong?
Thanks

采纳的回答

Shane L
Shane L 2019-8-8
As you noted, your t and image arrays are 1 x W, whereas your temp array is W x H. When you try to index
temp(:,x) = image;
you are trying to index a 1 x W array (image) into a W x 1 array (a column of temp).
If you would like your final array dimensions to be H x W, you can use repmat as follows:
t = 1:W;
image = (255*square(t.*2.*pi/P));
temp = repmat(image, H, 1);
Is this what you're looking for?

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Timing and presenting 2D and 3D stimuli 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by