Simulink: For Each Subsystem does not detect iteration amount - matlab

For some reason when I connect a For Each Subsystem to an output block it is unable to detect the iteration amount and will only iterate once:
When I connect it to something else, a scope in this case, it will iterate 5 times as it should:
The output connects to a demux with a dimension of 5 further in the simulation which in the first case fails:
Error in port widths or dimensions. Input port 1 of
'control/Camera/Motor bar/Demux1' is a one dimensional vector with 5
elements.

The output port was not the cause of the issue.
A little further on I had a Demux element which could not handle a one dimensional vector with 5 elements.
The error mentioned this properly.

Related

make a neural network continue number patterns

I discovered neural netwaorks a few time ago and i now how they work
but i have a question: how can I train a NN countinue number patterns,
e.g. 0,2,4,6,8 as a input and 10,12,14,16,18 as output.
I dont know how to make this, but I thought about a input [0,1,2,3,4] and
output [0,2,4,6,8],what means 0 is the first number of the stream and 3 the third
Can this work or what are the other ways.

Connect 4 and neural networks

I'm trying to code a Connect 4 - IA based on neural networks.
But it's the first time I use ANN, so I'm completely lost...
I found something that looks great, but need some explanations...
Structure
I'm ok with the input, but I don't understand the number of hiddens.
Also, the output should be the number of the colomn where to put the coin next turn, it means a value between 1 and 7.
But how could I get these values, using a sigmoid function ?

loop in Matlab/Simulink HDL [duplicate]

I have a system in Simulink/HDL coder (see below image please). I have 3 outputs and 3 inputs. I want my system to run 10 times. After each iteration it should select the outputs and use them as inputs. How I can do that?
Build a loop using a memory and a initial value block for each signal. The memory block allows you to access the previous iteration signal and the initial value block is used to set the input for the first iteration.
A simple example looping back one signal can be found here in the documentation
In your case it would look like this:
To get 10 iterations, set your simulation time corresponding. For example a fixed step discrete solver using 1s sample rate and 9s simulation time.

Simulink math operations on 2 bus signals

I need to make a Simulink block which receives a concatenation of a number of bus signals and performs the same math operations on the signals contained in the bus for each pair of consequent buses. The bus signals are of the same type and are non-virtual.
For the sake of the question, let's assume to have a concatenation of 4 simple buses, each containing a x and a y field. A bus of signals composed of a=x1+x2 and b=y1-y2 need to be made out of buses inputs 1,2 and 3,4. So, the output of the block should be a concatenation of 2 buses, the first containing information from the first pair of input buses, and the second one from the second pair.
An hard-to-scale way to do it is the following.
Are there any built-in Buses Math operations possibilities, or better ways to implement this? I could not find anything in Mathworks documentation, and simple operations block generate incompatibility errors.
You need to use For Each Subsystem Block. As shown in this example. Note that I called the bus BusTest and made the dimension and datatype of signals visible:
Now set the Signal Width parameter of that block to two so it divides input array into chunks of length 2:
Then move your logic into that block:

compare a network with multi value of a variable

I have a network and simulate it in netlogo.In my network i have n nodes with a random data from [0.1,2,...,19].
at the beginning one random node became sink and 3 random nodes start to send its data to sink.i declare a variable named gamma.after nodes send their data to sink,sink decide to whether store that data in its memory space or not base on gamma.after 0.5s this process repeat.at each time some nodes are sink and want some data.this is the way i distribute data in my network.
after all i have to change gamma from 0 to 1 to determine best value for that. and each time run my code to plot count of something.i mean:first run my code with gamma=1 and after run it again with gamma=0.98 and ...
if Entropy <= gamma
[
do something
]
If i press the setup button each time i change gamma my network setup change and i can not compare the same network with another gamma.
How can i compare my network with multi value of gammas??
I mean is that possible to save all my process and run it exaclly the same again?
You can use random-seed to always create the same network and then use a new seed (created and set with random-seed new-seed) to generate the random numbers and ask order etc for your processing. The tool BehaviorSpace will allow you to do many runs with different values of gamma.
Using this approach will guarantee you the same network. However, just because a particular value of gamma is best for one network, does not make it the best for other networks. So you could create multiple networks with different seeds and have NetLogo select each network (as #David suggests) or you could simply allow NetLogo to create the different networks and run many simulations so that you have a more robust answer that works over an 'average' network.
It is possible if you design some tests first, when you put random data each time you press setup the previous graph is not the same as the new one, thus you'll need to load the same data everytime you want to test.
An idea:
Make text files with the node data and the value of gamma. For 4 nodes you'd have something like:
dat1.txt
1 3 2 9
1
dat2.txt
1 3 2 9
0.98
dat3.txt
1 3 2 9
0.96
And so on...
You can genereate this files with a procedure and an specific seed (see random-numbers), this means that if you want to generate 30 tests (30 sets of 4 nodes in the above example), you'll need 30 different seeds.