matlab - How to remove the loop. (Vectorization) -


i trying remove "for" loop following matlab code. know not necessary in case, think if understand case, in future able apply same concept more complex case in necessary.

clear all; close all; clc;  u = @(n) (n>=0)*1.0;  % step function n = -5:25; x_a = zeros(size(n));  m = 0:10 % loop want remove     x_a = x_a + (((-1)^m)*u(-n+(2*m)))-(((-0.5)^(m+1))*(u(n-(2*m)))); end  figure(1);  stem(n,x_a);  grid; xlabel('sample number');  ylabel('amplitude x_a[n]'); 

thanks attention.

reshape m 3d matrix. apply same formula , results each m in 3d slices. sum on third dimension.

m = reshape(0:10,1,1,[]);    x_a = sum((((-1).^m).*u(-n+(2.*m)))-(((-0.5).^(m+1)).*(u(n-(2.*m)))),3); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -