C & Matlab Interview Questions
C & Matlab Interview Questions
The static storage class is used to declare an identifier that is a local variable either
to a function or a file and that exists and retains its value after control passes from
where it was declared.
The extern storage class is used to declare a global variable that will be known to the
functions in a file and capable of being known to all functions in a program. This storage
class has a duration that is permanent
The value or data of variable passed to function. It is known as call by value or pass
by value. So if the data passed is modified inside the function, the value is only changed
in the variable used inside the function
Instead of passing value of variable, pass the address of variable. It is known as call
by reference or pass by reference. Any updates made inside the called function will
modify the original value since we are directly modifying the content of the exact
memory location
Structure Union
In Structure, each member get In union, the total memory space is
separate space in memory. The allocated to be equal to the
total memory required to store a member with largest size. All other
structure variable is equal to the members share the same memory
sum of size of all member. space.
Example : Example
struct student union student
{ {
int id int id
char name char name
float marks float marks
}s1 }s1
In above example, 7 bytes (2 + 1 + 4) are In above example, 4 bytes are required to
required to store the structure variable s1. store the union variable s1, because a
variable mark is float type and it have
largest size (4 byte).
We can access any member in any We can access only that variable
sequence whose value is recently stored.
s1.id = 20; s1.id = 20;
s1.marks = 91.2; s1.marks = 91.2;
printf(“%d”,sl.id); printf(“%d”,sl.id);
Functions − functions files are also program files with .m extension. Functions
can accept inputs and return outputs. Internal variables are local to the function.
8. Difference between script and function script?
Scripts do not accept inputs and do not return any outputs.
Functions can accept inputs and return outputs.
MATLAB Simulink Interview Questions
Bus Creator: The Bus Creator block combines a set of signals into a bus. To bundle a
group of signals with a Bus Creator bloc. You can connect any type of signal to the
inputs, including other bus signals
The Bus Creator block accepts and outputs real or complex values of any data type
supported by Simulink, including fixed-point and enumerated data types, as well as
bus objects.
Bus selector Select signals from incoming bus. The block can output the specified
elements as separate signals or as a new bus.
When the block outputs separate elements, it outputs each element from a separate
port from top to bottom of the block.
Mux: The Mux block combines its inputs into a single vector output. An input can be
a scalar or vector signal. All inputs must be of the same data type and numeric type.
The elements of the vector output signal take their order from the top to bottom, or
left to right, input port signals.
Demux: The Demux block extracts the components of an input signal and outputs
the components as separate signals. The output signals are ordered from top to
bottom output port.
The Demux block operates in either vector mode or bus selection mode, depending
on whether you selected the Bus selection mode parameter
The zero-crossing function passes through zero from a positive or negative value
when the corresponding discontinuity occurs. At the end of each simulation step,
Simulink asks each block that has registered zero-crossing variables to update the
variables. Usually this technique improves simulation run time, but it can cause some
simulations to halt before the intended completion time.
When the input is depending on output of some other block which will be
executed later time, then algebraic loop error will occur.
If the function primarily involves complicated logical operations, use State flow
diagrams.
State flow should be used to implement modal logic – where the control function
to be performed at the current time depends on a combination of past and
present logical conditions.
Note:
If the primary nature of the function is logical, but some simple numerical
calculations are done to support the logic, implement the simple numerical
functions using the State flow action language.
If the primary nature of the function is numeric, but some simple logical
operations are done to support the arithmetic, implement the simple logical
functions with Simulink blocks.
If the primary nature of the function is logical, and some complicated numerical
calculations must be done to support the logic, use a Simulink subsystem to
implement the numerical calculations. The State flow software should invoke the
execution of this subsystem, using a function-call.
10. Tell me which are the mandatory for MAAB?
Block Resizing: - All blocks in a model must be sized such that their icon is completely
visible and recognizable. In particular, any text displayed (for example, tunable
parameters, filenames, or equations) in the icon must be readable.
Unconnected signals, block inputs and block outputs
In addition:
Combine multiple signals into single signal. The Merge block combines its inputs
into a single output line whose value at any time is equal to the most recently computed
output of its driving blocks. You can specify any number of inputs by setting the block's
Number of inputs parameter.
Simulink offers:
MIL
Models runs in a virtual environment
Functional models – at the system level
Implementation models – at an individual module and a whole system levels
SIL
PIL
HIL
Enabled subsystems are subsystems that execute at each simulation step for
which the control signal has a positive value.
An enabled subsystem has a single control input, which can be a scalar or a vector.
If the input is a scalar, the subsystem executes if the input value is greater than
zero.
If the input is a vector, the subsystem executes if any one of the vector elements
is greater than zero.
Choose held to cause the states to maintain their most recent values.
Choose reset to cause the states to revert to their initial conditions
16. Triggered Subsystems
Triggered subsystems are subsystems that execute each time a trigger event occurs. A
triggered subsystem has a single control input, called the trigger input that determines
whether the subsystem executes. You can choose from three types of trigger events to
force a triggered subsystem to begin execution:
rising triggers execution of the subsystem when the control signal rises from a
negative or zero value to a positive value (or zero if the initial value is negative).
falling triggers execution of the subsystem when the control signal falls from a
positive or a zero value to a negative value (or zero if the initial value is positive).
either triggers execution of the subsystem when the signal is either rising or
falling.
17. What is meant by Subsystem?
Both fixed-step and variable-step solvers compute the next simulation time as the
sum of the current simulation time. It is known as step size
Variable-step solvers: solve the model at, the step size can vary from step to step,
depending on the model dynamics, reducing the step size to increase accuracy
Fixed-step solvers: solve the model at regular time intervals from the beginning to the
end of the simulation. Generally, decreasing the step size increases the accuracy of the
results while increasing the time required to simulate the system.
It computes the next simulation time as the sum of the current simulation time and a
quantity known as the step size.
21. How you will choose the solver?
If you plan to generate code from your model and run the code on a real-time
computer system, choose a fixed-step solver to simulate the model because you cannot
map the variable-step size to the real-time clock.
If you do not plan to deploy your model as generated code, the choice between
a variable-step and a fixed-step solver depends on the dynamics of your model. A
variable-step solver might shorten the simulation time of your model significantly
In Matlab, we can import data from xlsx, xml, text, image, and video with
respective import, export functions.
In Simulink, we can import data from xlsx and text files with help of Signal
builders. Also using from workspace & from file blocks.
Black box Testing: Black Box Testing is a software testing method in which the
internal structure/ design/ model/implementation of the Product being tested is NOT
known to the tester.
White box Testing: (Transparent Testing): It is opposite to black box where every
structure of the product should be known to the tester. Unit, Integration and System
Level testing can be performed through this process
Unit testing
Integration testing
System testing
Regression testing
25. What is advantage of m files over Simulink/state flow?
M scripting allows us to define and design much more complex models like
BLDC/SRM motor with user defined specifications unlike Simulink which are predefined.
26. How to transfer the data from one subsystem to another executing at different sample
times?
Using Rate Transition Block. The Rate Transition block transfers data from the output
of a block operating at one rate to the input of a block operating at a different rate. Use
the block parameters to trade data integrity and deterministic transfer for faster
response or lower memory requirements
open_system(‘model_name’); or load_system(‘model_name’);
rtwbuild(‘model_name’);
close_system(‘model_name’);
exit;
States can be active or inactive. The activity or inactivity of a state can change
depending on events and conditions.
Every state (or chart) has a decomposition that dictates what type of substates the
state (or chart) can contain. All substates of a superstate must be of the same type as
the superstate decomposition. State decomposition can be Exclusive (OR) or parallel
(AND).
Exclusive OR: Substates with solid borders indicate EXCLUSIVE OR state decomposition.
Use this decomposition to describe operating modes that are mutually exclusive. When
a state has exclusive OR decomposition, only one substate can be active at a time.
Parallel AND: Substates with dashed borders indicate PARALLEL AND decomposition.
Use this decomposition to describe concurrent operating modes. When a state has
parallel (AND) decomposition, all substates are active at the same time.
Transitions can have different action types, which include event or message triggers,
conditions, condition actions, and transition actions. The action types follow the label
notation with this general format:
event_or_message trigger[condition]{condition_action}/{transition_action}
An inner transition is a transition that does not exit the source state. Inner
transitions are powerful when defined for superstates with exclusive (OR)
decomposition
A history junction represents historical decision points in the Stateflow chart. The
decision points are based on historical data relative to state activity. Placing a history
junction in a superstate indicates that historical state activity information is used to
determine the next state to become active. The history junction applies only to the level
of the hierarchy in which it appears
9. What Is a Connective Junction?
Temporal logic controls execution of a chart in terms of time. In state actions and
transitions, you can use two types of temporal logic: event-based and absolute-time. To
operate on these recurring events or simulation time, you use built-in functions called
temporal logic operators.
Stateflow charts can contain sequential decision logic based on state machines. A
finite state machine is a representation of an event-driven (reactive) system. In an
event-driven system, the system makes a transition from one state (mode) to another, if
the condition defining the change is true.
For example, you can use a state machine to represent the automatic transmission
of a car. The transmission has these operating states: park, reverse, neutral, drive, and
low. As the driver shifts from one position to another, the system makes a transition
from one state to another, for example, from park to reverse.
A Stateflow chart can contain sequential and combinatorial logic in the form of state
transition diagrams, flow charts, state transition tables, and truth tables. A state
transition diagram is a graphical representation of a finite state machine.
Use one of the keywords sec, msec, or usec to define simulation time in seconds,
milliseconds, or microseconds that have elapsed since activation of a state. These
keywords are valid only in state actions and in transitions that originate from states.
14. What is the difference Between Flow Charts and State Transition Diagrams?
A flow chart is used for combinatorial design. It is a stateless flow chart because it
cannot maintain its active state between updates. As a result, a flow chart always begins
executing from a default transition and ends at a terminating junction (a junction that
has no valid outgoing transitions).
By contrast, a state transition diagram is used for sequential design. It stores its
current state in memory to preserve local data and activity between updates. As a
result, state diagrams can begin executing where they left off in the previous time step,
making them suitable for modeling reactive or supervisory systems that depend on
history. In these kinds of systems, the current result depends on a previous result.