How to repeat an input command without using loops?
5 次查看(过去 30 天)
显示 更早的评论
So, Im working on an assignment for a class, and the question being asked is for me to code a self made function where I add up the combined resistances of a 'N' number of resistors. So far, I've got the base aspects of the function complete, but what I was planning to do is repeat a input command 'N' number of times so that you could enter the resistor value for each 'N" value. However, part of the assignment is to not use loops. I've tried using some repeat commands but as of yet have been unable to make any of them work. is there something else that I should use instead?
1 个评论
Walter Roberson
2018-9-17
while loops is probably what is expected.
There are also ways to hide for loops using arrayfun() or cellfun() or similar.
回答(1 个)
Sai Teja Paidimarri
2020-6-19
Hi Cole Wamsely,
It is possible to repeat variable n number of times without loop if you are already using sequential circuit or if you can generate clock or any pulse externally.
Simulink implementation: clock generator, switch case and if blocks are required.
Matlab implementation: switch case, if and external clock input is required.
Then you can follow these steps
1.clock generation if it is not clear then current state becomes next state and initial case 1.
2.switch case will run on current state and in case 1 specify next state as case 2.
3.In case 2 specify next case as case 1 and loop can be repeated for n number of times.
4.use variable in switch case to keep an eye on count, Stop the loop using conditional if on nth iteration.Otherwise one loop function is expected.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Sources 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!