MATLAB Answers

How can I write a function that replaces all of the multiples of eight or nine in a vector with seven, unless the multiple of eight or nine is also a multiple of seven.

1 view (last 30 days)
Zhiqing Wang
Zhiqing Wang on 30 May 2020
Answered: Ameer Hamza on 30 May 2020
How can I write a function that replaces all of the multiples of eight or nine in a vector with seven, unless the multiple of eight or nine is also a multiple of seven.

  0 Comments

Sign in to comment.

Answers (1)

Ameer Hamza
Ameer Hamza on 30 May 2020
Something like this
x = 1:1000;
mul7 = mod(x, 7)==0;
mul8 = mod(x, 8)==0;
mul9 = mod(x, 9)==0;
mask = (mul8 | mul9) & (~mul7);
x(mask) = 7;

  0 Comments

Sign in to comment.

Tags


Translated by