## What is the syntax to access a particular member in an array?

### Rainer (view profile)

on 29 Jul 2014
Latest activity Commented on by Michael Haderlein

on 30 Jul 2014

### Image Analyst (view profile)

Hi, I have an array x=[1 2 3 4 5].
I then manipulate x, e.g. (A*x/B+C-D)...How can I determine the third member of the manipulated array?
This works but i feel there is a simpler way:
temp=(A*x/B+C-D);
temp(3)
Is there a way to do something like
(A*x/B+C-D)(3)?

Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

on 29 Jul 2014
There is no simpler way. I think also that you tried what you are asking about and it didn't work

### Image Analyst (view profile)

on 29 Jul 2014

No other way. You're doing it correctly. That (temp(3)) is about as simple as it gets. What do you want - just a single character? You will write programs that are thousands of lines long, and referring to temp(3) is so so very trivial in comparison to the rest of your program that you should not worry about it.

Image Analyst

### Image Analyst (view profile)

on 29 Jul 2014
By the way, I think the alternate way you suggested is more confusing/ambiguous/deceptive. Someone might think you wanted to multiply that expression by the number 3. The first way is much more explicit and obvious what you meant and memory is cheap and plentiful so don't worry about using a few dozen or a few million more elements.
Rainer

### Rainer (view profile)

on 29 Jul 2014
Great, thanks for the answer. Just thought I'd check.

on 29 Jul 2014

Actually, I sometimes also don't want to assign some intermediate result to an extra variable. Tucker McClure has included a function in his collection of functional programming constructs which I use in this case:
>> x=1:5;
>> paren(x.^2,3)
ans =
9

Rainer

### Rainer (view profile)

on 29 Jul 2014
Holy smokes, that is exactly what i needed.
Image Analyst

### Image Analyst (view profile)

on 29 Jul 2014
Just gives an error for me:
>> x=1:5;
>> paren(x.^2,3)
Attempt to execute SCRIPT paren as a function:
C:\Program Files (x86)\MATLAB\R2014a\toolbox\matlab\ops\paren.m