# Using nested loops, write a Matlab program that goes through all elements of a matrix (2D array) and replaces every element that is either a multiple of 5 or 7 with -1.

26 visualizzazioni (ultimi 30 giorni)
Ciara Gornoski il 2 Apr 2018
This is what I have so far...
A=input('enter an array');
num_rows = size(A,1);
num_cols = size(A,2);
for i=1:1:num_rows
for j=1:1:num_cols
if A(i,j)/ 5 or 7 = integer
fprintf('-1')
end
end
end
I'm not sure how to identify the multiples of 5 and 7 and make them replace that with the -1
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (1)

Roger Stafford il 2 Apr 2018
if round(x/5)==x/5 | round(x/7)==x/7
(Doing fprintf('-1') just prints out "-1" and is totally useless for your purposes.)
##### 2 CommentiMostra NessunoNascondi Nessuno
Ciara Gornoski il 2 Apr 2018
Modificato: Walter Roberson il 2 Apr 2018
I did this and I'm still not getting anything.
A=input('enter an array');
num_rows = size(A,1);
num_cols = size(A,2);
for i=1:1:num_rows
for j=1:1:num_cols
if round(A(i,j)/5)==A(i,j)/5 || round(A(i,j)/7)==A(i,j)/7
end
end
end
I'm just able to input an array but it doesn't give me an output.
Walter Roberson il 2 Apr 2018
if ...
A(i,j) = -1;

Accedi per commentare.

### Categorie

Scopri di più su Satellite Mission Analysis in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by