フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How do you determine which numbers in a vector are factors of 144 by indexing through it using loops?

1 回表示 (過去 30 日間)
user92131
user92131 2016 年 10 月 16 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I have a vector of random integer from 1 to 100 with the amount of elements that a user inputs. All operations must be performed using loops, not built-in functions or array operations.
clc
clear
elements = input('Enter how many elements are in the vector: ');
rng('shuffle')
vector = randi([1,100],1,elements)
How do I determine how many numbers in the vector are factors of 144 and what those number are?

回答 (2 件)

Walter Roberson
Walter Roberson 2016 年 10 月 16 日

Marc Jakobi
Marc Jakobi 2016 年 10 月 16 日
tf = false(size(vector));
for i = 1:length(vector)
if mod(144,vector(i)) == 0
tf(i) = true;
end
end
factors = vector(tf);
Or instead of mod(), you could do
if 144./double(vector(i)) == round(144./double(vector(i)))

この質問は閉じられています。

製品

Community Treasure Hunt

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

Start Hunting!

Translated by