Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations pierreick on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Array Addition

Status
Not open for further replies.

KatiLynSki

Civil/Environmental
May 16, 2005
33
I am having a very difficult time with a very simple problem.

I have an array, RoadWidth[n (where n= 1..48). I want to add a constant to each of the values in the array. In my head this can be accomplished with a simple for loop but I just can't get it to work.

for n = 1..48
SubgradeWidth[n = (RoadWidth[n) + 2

This is obviously the wrong way to do it. (I know I could just add an array of the same size that has a 2 in each variable spots but that just seems like it would take up a lot more room on my calc sheet and would take more effort to change the 2 to any other variable that I want at some later date.)

Any insight on this lovely Friday morning?

THANKS

-KD
 
Replies continue below

Recommended for you

I just tried defining road as a matrix (48x1). Then define subgrade= road+2. It works fine. The result is a matrix with individual values 2 greater than road. You maybe be having a problem using the range variable n.
 
rd78-

Thank you. I knew it was something simple.

-KD
 
there's a few ways of doing it, the obvious one being

n:1;48
SubgradeWidth[n: 2+RoadWidth[n


Cheers

Greg Locock

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
Matrix + Constant
Simply typr
SubgradeWidth:Matrix+2

Y

(to get it right assume you are wrong)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor