# 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.

12 views (last 30 days)
Ciara Gornoski on 2 Apr 2018
Commented: Walter Roberson on 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

Roger Stafford on 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 CommentsShow 1 older commentHide 1 older comment
Walter Roberson on 2 Apr 2018
if ...
A(i,j) = -1;
{"ft_lang_label":"__label__en","ft_lang_prob":0.80977476,"math_prob":0.90929896,"size":1002,"snap":"2023-14-2023-23","text_gpt3_token_len":287,"char_repetition_ratio":0.08917835,"word_repetition_ratio":0.0,"special_character_ratio":0.2964072,"punctuation_ratio":0.0913242,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95673066,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-05-28T03:33:20Z\",\"WARC-Record-ID\":\"<urn:uuid:00fbb553-17c1-4800-bd7b-f0e6b2497dbb>\",\"Content-Length\":\"130842\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:0f05a296-9bf4-44e5-8d2c-fdf1d1fb8180>\",\"WARC-Concurrent-To\":\"<urn:uuid:5b20312a-a7e5-4fe9-81f4-0d70b583077d>\",\"WARC-IP-Address\":\"184.28.45.132\",\"WARC-Target-URI\":\"https://se.mathworks.com/matlabcentral/answers/392040-using-nested-loops-write-a-matlab-program-that-goes-through-all-elements-of-a-matrix-2d-array-and\",\"WARC-Payload-Digest\":\"sha1:K5XQBZ2I6QKYTJHNWAZOCPTJJ3RBPUG2\",\"WARC-Block-Digest\":\"sha1:NAEB5VR2WJUMXTPAKDSBGUWYVWIOMWO3\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224643462.13_warc_CC-MAIN-20230528015553-20230528045553-00417.warc.gz\"}"}