フィルターのクリア

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

2 ビュー (過去 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 Center および File ExchangeTiming 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