Asked by sriram amarnath
on 24 Jun 2019 at 1:30

The below code is to calculate the modes on a plate. The for loops are not using all the values of m & n

% Modes on a plate

Lx=0.286; % length of plate(m)

Lz=0.198; % breadth of plate(m)

for m = 1:1000 % mode numbers

for n = 1:10

func=((n.*pi)./Lx).^2 +((m.*pi)./Lz).^2;% summation function n=1:10 & m= 1:1000

end

end

Answer by madhan ravi
on 24 Jun 2019 at 1:59

Edited by madhan ravi
on 24 Jun 2019 at 3:32

Accepted Answer

The same goal can be achieved trivially using meshgrid() or ndgrid() without a loop:

% Modes on a plate

Lx=0.286; % length of plate(m)

Lz=0.198; % breadth of plate(m)

n=10;

m=1000;

[Y,X]= ndgrid(1:m,1:n);

func=(X*pi/Lx).^2 +(Y*pi/Lz).^2;

But the modication in your code is as follows:

func = zeros(1000,10); % before loop

func(m,n) = ... %just add (m,n) next to func inside the loop

sriram amarnath
on 24 Jun 2019 at 12:48

Thanks madhan ravi your a saviour!

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## dpb (view profile)

Direct link to this comment:https://in.mathworks.com/matlabcentral/answers/468517-for-loops-not-working#comment_717515

## sriram amarnath (view profile)

Direct link to this comment:https://in.mathworks.com/matlabcentral/answers/468517-for-loops-not-working#comment_717726

Sign in to comment.