I just to confirm my syntax of abs and mode

1 view (last 30 days)
I have wrote it like this
x(mod(n, 2) == 0) = 5 * alpha .^ (abs(n(mod(n, 2) == 0))/2);
Is this one is right?

Answers (1)

Walter Roberson
Walter Roberson on 19 May 2023
Not exactly.
syms alpha
n = [1 2 3 4 5]
n = 1×5
1 2 3 4 5
x(mod(n, 2) == 0) = 5 * alpha .^ (abs(n(mod(n, 2) == 0))/2)
x = 
length(n)
ans = 5
length(x)
ans = 4
  5 Comments
Walter Roberson
Walter Roberson on 19 May 2023
By the way (hint):
[false false true false] .* [1 2 3 4]
ans = 1×4
0 0 3 0
Torsten
Torsten on 20 May 2023
n negative or 0 is not a problem for Zamer's code, as there is no indexing by n
I meant accessing the values of the sequence for n <= 0. The most natural way would be x(n) what does not work.

Sign in to comment.

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!