Storing a Square Wave in an array that is more than just one row
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Brendan Collins
le 8 Août 2019
Commenté : Brendan Collins
le 13 Août 2019
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
0 commentaires
Réponse acceptée
Shane L
le 8 Août 2019
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?
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Timing and presenting 2D and 3D stimuli dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!