Clear Filters
Clear Filters

How to repeat an input command without using loops?

10 views (last 30 days)
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 Comment
Walter Roberson
Walter Roberson on 17 Sep 2018
while loops is probably what is expected.
There are also ways to hide for loops using arrayfun() or cellfun() or similar.

Sign in to comment.

Answers (1)

Sai Teja Paidimarri
Sai Teja Paidimarri on 19 Jun 2020
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.

Tags

Community Treasure Hunt

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

Start Hunting!