How to use the compute function in dart to pass more than one parameter? - flutter

I need to use isolate to compute a rather heavy calculation for the app im developing.
All i managed to find is how to pass a single to compute function
but i need to pass more than 1 param to the function, can anyone tell me the synthax
compute(function,param);

Related

Can I make parameters mandatory without creating a parameter block for every function?

Is it possible to have powershell make every parameter for every function in a file mandatory without having to add a parameter block to every single function?
Sadly you're going to have to add [Parameter(Mandatory=$true)] to all of your parameters.
Is your problem that you need the same parameters across a lot of different functions? One thing I am trying to do to simplify my scripts is if a task is happening a lot of times throughout my module, I am making it into it's own function and then calling the function instead of creating the same logic over and over.

Create Custom Functions in MATLAB

I'm having problems with functions in matlab, I need to do an equalizer that uses 3 filter (high pass, low pass, band pass), I've created three diferent scripts to do this filters, now I want my main program of the equalizer call this 3 scripts, someone knows how to do this? I've serach in the internet but i don't found anything that can help me.
If I understand you correctly, you are wanting to pass the filters you have created in as functions to some script that will do the processing. This is fairly straightforward to do by passing in a function handle as an argument. If, for example, you have a function called high_pass_filter (written in a file high_pass_filter.m), then you can pass it in as an argument to a function using something like:
do_processing(#high_pass_filter, arguments);
In the function do_processing, it has as its definition something like
function do_processing(filter, arguments)
then to apply the filter (i.e. execute high_pass_filter.m), you just need to write
filter(arguments_for_filter_function);
Then you can call the same processing function for the three different filters.
More on function handles can be found on this page of the Matlab documentation

Simulink - How to create independent custom blocks using callback functions

I am currently coding a new library with several models in it (I am used to Matlab, but not to Simulink). I am able to create a model with block parameters, let's say parameter 'p', and a callback function (initfct) which uses this parameter to compute specific values used inside my model (let say a simple gain K=K(p)).
My problem is that my parameter 'p' and 'K' are available directly on the workspace, what I don't want to. Moreover, if I use twice or more this model in a system, the two models share always the same 'K', which also I don't want to.
So how I can make these variables 'p' and 'K' independent when I use my custom model several time, and to prevent these variables to be viewed in the workspace ?
Should I use "Reference models", but I am not familiar with this feature ... ?
Thanks for you answer,
Michael
Within a callback, gcb returns the path to the block which currently executes the callback. Having the path, you can use get_param to access the parameters.
Just for demonstation purposes, insert the following to the MoveFcn of a delay block:
set_param(gcb,'DelayLength',num2str(randi(10)))
It will randomly change the delay whenever the block is moved.
I am not sure if my answer explains everything you need. It might be that you also need a Mask. If you think this answer is incomplete, please update your question and include a small example model demonstrating your problem.
Thanks, with your help I was able to solve the problem.
To be more specific if someone else has the same problem : you need in your mask to declare also internal variables used by the callback function. Unchecked the relevant options so that they not appear as standard input parameters of your model.
My problem was also to use num2str instead of mat2str (when the gain was a matrix acting on multiple inputs).

a handle to shorten the name of stuct/class in matlab

I have a struct with relative sophisticated data trees. for example:
class.data.head{1}.data2
What I wish to get is a variable named data2_link to link with address class.data.head{1}.data2, so that:
(1) if there is any change on class.data.head{1}.data2, it will automatically reflected to data2_link as well, and vise versa.
(2) I do not have to type the long name to access the data at class.data.head{1}.data2.
Thanks!
Matlab does not support references. The only exception is handle which allows references to objects.
To use it, data2 must be an object with superclass handle, then you could simply write:
data2_link=class.data.head{1}.data2
Note that object oriented matlab significantly slows down your code unless you use Matlab 2015b or newer.
There is an extremely discouraged way to do it. you can create a function handle that evaluates the desired expression:
data2_link = #() evalin('caller', 'class.data.head{1}.data2')
Now every time you need that expression just call it using
>> data2_link()
The extra parentheses are necessary to invoke the function defined by function handle.
Just got another idea, you could use subsref to access it and subassign to write. It is not really what I would call a reference because you still need S, but it probably comes as close to it as possible without using OOP.
S=substruct('.','data','.','head','{}',{1},'.','data2')
%previous line is the same as: S=struct('type',{'.','.','{}','.'},'subs',{'data','head',{1},'data2'})
f=subsref(class,S)

Find indirect calls to specific built-in MATLAB function

What do I want?
I am looking for a way to detect all points in my code where a specific function is called.
Why do I want it?
Some examples:
Some output comes out sorted or randomized, and I want to know where this happens
I am considering to change/overload a function and want to know in which part of my code this could have impact
What have I tried?
I tried placing a breakpoint in the file that was called. This only works for non builtin functions which are called from short running code that always executes everything.
I tried 'find files', this way I can easily find direct calls to sort but it is not so easy to find a call to sort invoked by unique for example.
I have tried depfun, it tells me:
whether something will be called
from where non-builtin functions will be called
I thought of overloading the builtin function, but feels like a last resort for me as I am afraid to make a mess. | Edit: Also it probably won't help due to function precedence.
The question
What is the best way to track all potential (in)direct function calls from a specific function to a specific (built-in)function.
I don't exactly understand your use case, but I guess most of the information you want can be obtained using dbstack, which gives you the call-stack of all the parent functions calling a certain function. I think the easiest way is to overload built-in functions something like this (I tried to overload min):
function varargout = min(varargin)
% print info before function call
disp('Wrapped function called with inputs:')
disp(varargin)
[stack,I] = dbstack();
disp('Call stack:')
for i=1:length(stack)
fprintf('level %i: called from line %i in file %s\n', ...
i, stack(i).line, stack(i).file);
end
% call original function
[varargout{1:nargout}] = builtin('min', varargin{:});
% print info after function call
disp('Result of wrapped function:')
disp(varargout)
I tried to test this, but I could not make it work unfortunately, matlab keeps on using the original function, even after playing a lot with addpath. Not sure what I did wrong there, but I hope this gets you started ...
Built-in functions take precedence over functions in local folder or in path. There are two ways you can overload a built-in for direct calls from your own code. By putting your function in a private folder under the same directory where your other MATLAB functions are. This is easier if you are not already using private folder. You can rename your private folder once you are done investigating.
Another way is to use packages and importing them. You put all your override functions in a folder (e.g. +do_not_use). Then in the function where you suspect built-in calls are made add the line "import do_not_use.*;". This will make calls go to the functions in +do_not_use directory first. Once you are done checking you can use "clear import" to clear all imports. This is not easy to use if you have too many functions and do not know in which function you need to add import.
In addition to this, for each of the function you need to follow Bas Swinckels answer for the function body.
Function precedence order.
Those two methods does not work for indirect calls which are not from your own code. For indirect calls I can only think of one way where you create your own class based on built-in type. For example, if you work only on double precision types, you need to create your own class which inherits from double and override the methods you want to detect. Then pass this class as input to your code. Your code should work fine (assuming you are not using class(x) to decide code paths) since the new class should behave like a double data type. This option will not work if your output data is not created from your input data. See subclassing built-in types.
Did you try depfun?
The doc shows results similar to the ones you request.
doc depfun:
...
[list, builtins, classes, prob_files, prob_sym, eval_strings, called_from, java_classes] = depfun('fun') creates additional cell arrays or structure arrays containing information about any problems with the depfun search and about where the functions in list are invoked. The additional outputs are ...
Looks to me you could just filter the results for your function.
Though need to warn you - usually it takes forever to analyze code.