Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Storing loop values -- non-integer step sizes

Subject: Storing loop values -- non-integer step sizes

From: James

Date: 6 Dec, 2012 21:27:09

Message: 1 of 3

Hi,

I am attempting to store a value from a for loop every time the loop executes, but the step size of the loop begins with zero and increments at a non-integer value until it reaches a specific value. I have tried several various approaches, with my most recent approach below.

All I want to do is store all of the values returned by the function "machsolve" into an array.

Any ideas?


N=100; %number of prandtl meyer angle increments

M=2; %design exit mach number
g = 1.4; %specific heat ratio of air

A = sqrt((g+1)/(g-1));
B = atan(sqrt(((g-1)/(g+1))*(M^2-1)));
C = atan(sqrt(M^2-1));

nu = A*B-C; %prandtl meyer function to calculate maximum turn angle

thetaexit = nu;

i = thetaexit/N; %incremental step size

for dnu=0:i:thetaexit
    MM = machsolve(dnu, g); %call function that returns MM
    M(:,1) = MM %latest attempt at storing the returned values
end

Thanks ,

Subject: Storing loop values -- non-integer step sizes

From: Roger Stafford

Date: 6 Dec, 2012 22:04:09

Message: 2 of 3

"James " <jpk77@msstate.edu> wrote in message <k9r2jd$28k$1@newscl01ah.mathworks.com>...
> i = thetaexit/N; %incremental step size
> for dnu=0:i:thetaexit
> MM = machsolve(dnu, g); %call function that returns MM
> M(:,1) = MM %latest attempt at storing the returned values
> end
- - - - - - - - -
  As it is, your for-loop is not generating an index that can be used to store your values in 'M'. Do something like this instead:

 dnu = linspace(0,thetaexit,N+1);
 for ix = 1:N+1
  M(ix) = machsolve(dnu(ix),g);
 end

Roger Stafford

Subject: Storing loop values -- non-integer step sizes

From: James

Date: 6 Dec, 2012 23:17:10

Message: 3 of 3

"Roger Stafford" wrote in message <k9r4op$agc$1@newscl01ah.mathworks.com>...
> "James " <jpk77@msstate.edu> wrote in message <k9r2jd$28k$1@newscl01ah.mathworks.com>...
> > i = thetaexit/N; %incremental step size
> > for dnu=0:i:thetaexit
> > MM = machsolve(dnu, g); %call function that returns MM
> > M(:,1) = MM %latest attempt at storing the returned values
> > end
> - - - - - - - - -
> As it is, your for-loop is not generating an index that can be used to store your values in 'M'. Do something like this instead:
>
> dnu = linspace(0,thetaexit,N+1);
> for ix = 1:N+1
> M(ix) = machsolve(dnu(ix),g);
> end
>
> Roger Stafford

Perfect!

Thanks Roger!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us