How to repeat an input command without using loops?

9 ビュー (過去 30 日間)
Cole Wamsley
Cole Wamsley 2018 年 9 月 17 日
回答済み: Sai Teja Paidimarri 2020 年 6 月 19 日
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
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
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.

カテゴリ

Help Center および File ExchangeSources についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by