how to select single input from multiple output in Simulink? - simulation

Could any one tell me how can i use a Multiport switch in the following example. i can use alternatively MATLAB funtion block with M script but its slow. 2 days before i try to use a sum block as shown in figure2 and i thought i am genius and and i was succed. But Today Morning i am getting a 'Ghombaro Result'(Unexpeted Result)' i.e during simulation mode when i am changing my input level the pervious output is remain same and its adding up i thought it will replace it with ZERO ... :( ..... is there any way to do it by using another block or with any idea...
.
Thank you...............

Use a Merge block, to merge all input from your 'If Action Subsystems', set Initial Output as 0.
Connect the output of merge block to the 'Display' block

Related

how to show the linearization result in Dymola?

I tried to use the linearization function in Dymola, but it seems when the result's dimension is large, Dymola won't show the result.
My question is:
How could I print the result or where to find it?
What you can do, is assign the result to a variable. This can be done using the Outputs group as shown in the screenshot below. If you e.g. enter "sys" in the field for ss, you will get a record sys, in which you can access the matrices/vectors by typing sys.A, sys.B etc., which I've tested for a system of size 200x200. Typing this into the command line will display the content. Of course this record not only for outputting it, but also for post-processing.
The only thing this actually does, is modify the call from Modelica_LinearSystems2.ModelAnalysis.Linearize("ModelName") to sys=Modelica_LinearSystems2.ModelAnalysis.Linearize("ModelName"), so it can be done in the Commands window as well.
Call the function from the command line and capture the output. Then you can do with it what ever you want.
Everything you find in the Linear Analysis toolbar is part of the library Modelica_LinearSystems2. The Linearize item in this menu calls the function
Modelica_LinearSystems2.ModelAnalysis.Linearize("<your-model>")
which is also printed to the command line. The function returns the operator record Modelica_LinearSystems2.StateSpace, which contains all the info you are interested in. The default behavior of Dymola is to call the String method of this operator record and print it to the command line. If you look at the source code of Modelica_LinearSystems2.StateSpace.'String' you can see this at the start of the algorithm section:
// If system is too large, do not print the matrices
if size(ss.A,1) > 50 or size(ss.B, 2) > 50 or size(ss.C, 1) > 50 then
...
On the command line you can capture the operator record in a variable like this:
stateSpace = Modelica_LinearSystems2.ModelAnalysis.Linearize("<your-model>");
And then access the values on the command line via
stateSpace.A
stateSpace.B
stateSpace.C
stateSpace.D
For a nice html report you can also pass the operator record to one of the analysis functions:
Modelica_LinearSystems2.StateSpace.Analysis.analysis2.printSystem(stateSpace)
This creates the file systemAnalysis.html in your working directory, containing a nice visual presentation of your system.

How to generate new numbers if i run the program everytime from the begining?

I am working on CATScript in optimization of a part.
When I run the script everytime it shoud provide numbers in ascending order.
For example if I run the program for the first time it should provide the output as " 1 "
and if I run the program again it shoud provide the output as " 2 " and so on.
I am stuck with this and I could not figure out th logic that we have to use here.
Looking forward for your help.
Thank you!!
An option (matlab based) could be to save a counter variable to a .mat-file at the end of the script, which is then loaded again at the beginning of the script.
That would allow you to keep track of how many times the script have been run.
In CATIA if it is being run multiple times on the same part/product, you could add a hidden, integer parameter to the specification tree and increment it each time the macro is run.
Another, more generic way would be to create a text file on the user's local and update the number in the text file.

How to keep the work space of executing method in matlab?

I want to use script file as function because somehow, I need to define methods in script file and it is not possible in script file. However, when I defines script as function and execute it then I lose work space and I can not do further analysis of variables. I do not want to set breakpoints in code. Is there a way to keep work space alive for further analysis.
At the end of the function:
save filename;
evalin('caller','load filename');
I just got an evil solution:
%get all the var-names of the fcn-workspace
myVars=who('*')
for var=myVars'
assignin('base',var{:},eval(var{:}))
end
..this will work, but it is eval :)

Retrieve past results

Is it possible to retrieve previous results in the command window? For example i had some matrices and vectors in the command window and after an error the matlab was closed . Is it possible to retrieve them?
Thanks
No guarantees about what happens after a crash, but in general, use the command diary('filename.txt') to append all text in the CommandWindow -- not the Command History window -- to that text file.
(I dunno why MathWorks doesn't call the "CommandWindow" what it is, i.e. the Console, but there you are.)

How do I suppress the DOS window from Matlab?

I have 'inherited' Matlab code (A) that uses another compiled Matlab code (B). I do not have the source of B. B requires user intervention ('Hit return to continue'), and I need to use A in a loop. I need to do something so I would not need to hit Return each and every time until the loop is done.
The command I use in the loop is:
str='!start "Code_B" /low "c:\Code_B\bin\Code.exe" r';
eval(str)
Are there any other switches that I can use to suppress the call to 'Hit return' ?
Thanks
Katto
One way you could do this is to create a batch file that:
Starts the compiled Matlab program
Waits for the program to run (fixed delay?)
Uses a utility to send the program an Enter key
There are many (free) utilities that let you send keystrokes to a program.
Instead of calling Program B, you would call this batch file.
You can create a text file, let's say autoreturn.txt, with many empty lines (just end of line characters), over the number of loops you expect. Then add redirection of input from this at the end of your string:
str='!start "Code_B" /low "c:\Code_B\bin\Code.exe" r < autoreturn.txt';