Using matlab function block to output a histogram? - matlab

I am using a Matlab function block in Simulink model. In my case, the Matlab function block takes in an arbitrary number of signals as input signals and outputs signal values over time in the form of a histogram.
I need a little guidance regarding how to start with matlab function block coding. I have read the documentation and various other posts but could not work my way around it, probably because its a new topic for me and i am not a matlab programmer. Any help in this regard is appreciated.
Thank you.

Related

Sample sequence of points from continuous signal simulink

I have a Matlab function (created by me) that must be evaluated only at a given rate. I would like to sample the value of a signal, give to this function (discrete values) and then, the calculated output must be hold until the next value is available. Is there a way in simulink to do this? All answers I have found use quantizer + ZOH but in this case I still get "a continuum" (or almost it) of points to be evaluated by thsi function which is really slow. Changing the rate of simulink's solver is also not an option as the result of this function will be given for a continuous time system.
Any help will be highly appreciatted!
Thank you
Assuming by Matlab function you mean a MATLAB Function block, then it sounds as if all you need to do is make the block discrete. Do that by right-clicking on the block, going down to Block Properties and then in the resulting dialog enter your required sample time.
The block will then sample its input and generate an output (which is held between sample times) at each sample time.

normxcorr2 vs. normxcorr2_general in Matlab

There is a file called normxcorr2_general on MathWorks here that the author claims always gives correct answers while Matlab's built-in normxcorr2 gives incorrect answers when the two input matrices are close in size. After doing some testing, it is clear that the two functions do give significantly different outputs when the inputs are the same size.
Is normxcorr2_general actually more accurate? I don't have much experience in Matlab and I'm having trouble figuring that out from reading through the function script.
Edit: To clarify, if I understand it correctly then these functions are both implementing equation number (2) in this paper about computing normalized cross-correlations.

MATLAB function handles

Im working on a MatLab homework and don't understand quite what the task is. The homework states:
Create a MATLAB funciona in an .m file which receives a handle for a two-dimensional function and which creates a surface plot with a range of values input while the .m file is running.
I can't make sense of what I'm supposed to be doing. Could anyone provide such an example?
Your homework is to define a MATLAB function. As it is a homework, you should know how to do that.
The input variable for your function should be a handle for a two-dimensional function. Again, you should know what this means, or you should be able to figure it out (hence homework). Hint: help function_handle.
The function should read the plot ranges during runtime, i.e. interactively from the user (writing something into the command line). You should know how to do this.
And finally, your function has to plot the 2d surface (provided as input parameter) over the range (provided as interactive input). You should know how to do this.

Structure as input for a Matlab function Block

I have a, in my opinion, little problem using a Matlab-Function Block in a Simulink Model.
I want one of the inputs to be a structure.
But that doesn't work so easily, I've come across
suggestions on other semi-related problems, which tell about defining Simulink.Bus and so on,
but to be honest I don't understand how this can be applied on my problem.
It seems simple:
Structure as input for a Matlab function Block
But I don't know how.
Sorry for the inconvenience.
Regards BZAD
Within Simulink you create a Bus signal using the Bus Creator Block. This can then be fed into a MATLAB Function block, but only if an accompanying Simulink.Bus object is created in the Base Workspace.
See Types of Structures in MATLAB Function Blocks and Create Structures in MATLAB Function Blocks and the links off those pages for more information.

How can I call an m file in Simulink and put it to a block in my model?

How can I call an m file in Simulink and put it to a block in my model (without using an S function)? Does anybody have an idea? I'd really appreciate it.
If you're trying to apply a user-defined MATLAB function to Simulink signals, there are a few different ways to do this, depending on your objective. All options are available within the User-Defined Functions section of the Simulink library.
Use the MATLAB function block if you intend to generate code from your model. This block does have restrictions, the entire gamut of built-in MATLAB functions is not available.
Use the Interpreted MATLAB function block if you don't care about code generation, this block can make use of any functions.
Use the Fcn block if your m-file is trivial and contains a simple expression operating on the inputs. In this case you can type the expression directly into the block dialog and reference the input / output signals as shown in the documentation.
MATLAB Fcn block is the best solution to embed M-function file into Simulink model. However, be cautious which version of MATLAB you are using, e.g., with later versions of MATLAB Function Block can be implemented with M-function file with %#codegen and C compiler need to be with your MATLAB package. Good luck