I just to confirm my syntax of abs and mode

8 visualizzazioni (ultimi 30 giorni)
Zamer Chaudhary
Zamer Chaudhary il 19 Mag 2023
Commentato: Torsten il 20 Mag 2023
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?

Risposte (1)

Walter Roberson
Walter Roberson il 19 Mag 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 Commenti
Walter Roberson
Walter Roberson il 19 Mag 2023
By the way (hint):
[false false true false] .* [1 2 3 4]
ans = 1×4
0 0 3 0
Torsten
Torsten il 20 Mag 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.

Accedi per commentare.

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by