MATLAB Answers

# i need some help

1 view (last 30 days)
abdalrhman khalaf on 17 Feb 2020
Commented: Bob Nbob on 18 Feb 2020
i want to assign variable depend on anothor variable

#### 3 Comments

abdalrhman khalaf on 17 Feb 2020
n =
10
>> p10=2
p10 =
2
>> p{n}
somthing like that
JESUS DAVID ARIZA ROYETH on 17 Feb 2020
John D'Errico on 17 Feb 2020
Learn to use MATLAB as a vector and array language. After all, that is how it is designed to be used.

Sign in to comment.

### Answers (1)

Bob Nbob on 17 Feb 2020
Edited: Bob Nbob on 17 Feb 2020
If I'm understanding what you're trying to do, you're only missing parentheses.
>> n = 10;
>> p(10) = 2;
>> p(n)
p(n) =
2
You can also assign values in a similar manner.
>> n = 10;
>> p(n) = 2;
>> p(10)
p(10) =
2

#### 2 Comments

abdalrhman khalaf on 17 Feb 2020
Put if 0 it fails ...
Bob Nbob on 18 Feb 2020
Yes, because the value inside the parentheses is referencing a position within an array. You cannot call a 0 placement, because a 0 position doesn't make sense.

Sign in to comment.