Is it possible to automatically output many possibilities using a loop?
2 次查看(过去 30 天)
显示 更早的评论
I have the number let's say 100, I found its initial factors which are 4 and 50. I would then like to use these factors to divide by the input 100. 100/50= 2, then 50/2 = 25. You can see the pattern where the denominator becomes the numerator and the answer becomes the denominater but, I would like to know a way to do this automatically without the need of manually typing it down. All the possible outputs will then be stored in a cell array and displayed e.g. [50,4,2,25...]. It doesn't have to be ordered.
Is this possible? I have been trying to do this but have not achieved much progress.
0 个评论
采纳的回答
John D'Errico
2021-3-11
编辑:John D'Errico
2021-3-11
What you want to do does not seem to make a lot of sense, nor how you will get those initial factors. But I'm sure you have some plans for this.
N = 100;
F = [4 50];
F = [F,N./F];
F
I have no clue why you think you need a cell array to store them. But no loop is required as you can see,
You might consider what will happen if the number N was 36, for example, and one of the initial factors you found was 6. In that case, we might see that 36/6 == 6, so 6 will appear twice in that list.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!