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

조회 수: 1 (최근 30일)
Brendan Collins
Brendan Collins 2019년 8월 8일
댓글: Brendan Collins 2019년 8월 13일
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에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by