Storing a Square Wave in an array that is more than just one row
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Brendan Collins
el 8 de Ag. de 2019
Comentada: Brendan Collins
el 13 de Ag. de 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 comentarios
Respuesta aceptada
Shane L
el 8 de Ag. de 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?
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!