How to use find() method in simulink? - matlab

I have to translate the .m file to simulink but I don't have any idea about How to use find() method. The result of the find() method is variable vector, which is not allowed by the simulink. Does anybody can help? Thanks.

You can try using a matlab function block (or maybe a prelookup might work, depending on the application).

Use:
[index]=find(data,1)
The second parameter of find specifies how many indices you want to find. Now find outputs a constant length vector and can be used in simulink.

Perhaps you can do this with the Submatrix or Selector blocks. This answer may be helpful.

Related

derivate of a two variable function on one point ti-nspire

The image shows my problem (link)
I want to use that to do a Jacobian for a Multivariable method of aproximation. So There is a way to use that easily? or I have to put manually the partial derivatives like new functions?
I'm sorry for my english.
Firstly, you dont have to use images here, you can easily insert code pieces. As for your problem, i didnt understand it. Im sure you already know that you can define a Jacobian matrix function of 2 variables:
j2_fun(f1,f2):=[[derivative(f1,x),derivative(f1,y)][derivative(f2,x),derivative(f2,y)]]
... and call it later with specific arguments, and evaluate for some x,y:
g1:=x^2+y^2
g2:=x^2-y^2
d2:=j2_fun(g1,g2)
d2|x=3 and y=1
So staring from here, please define more clearly what would you like to do with this.

How can I create multiple inputs for a matlab function block?

I want to restrict the variable that I use as input for a matlab function block, it must be only able to increase.
To achieve that i have tried to compare the variable and the previous sample of it in a matlab function, but i don't know how to create two inputs. To solve that i've tried to use a mux, but then i get an error. And google doesn't give me an explanation how to use a mux signal as input for a matlab function.
So that leaves me here with this low-level question.
Thanks in advance for your help and time. Cheers.
To use multiple variables in a function, you need to modify your function declaration at the first line of your function. The reference syntax is:
function [y1,...,yN] = myfun(x1,...,xM)
where x1 through xM are inputs. Your declaration with two inputs might look something like:
function [returnValue] = hasIncreased(previousSample, variable)
See the Matlab Function Documentation for more information.

Matlab/Simulink : Replace a column in a matrix in Simulink

I just want to know if an easy method exists to replace entirely a column of a matrix by an another one ? I can do it by using recursively a concatenate block but it seems a bit onerous...
Thanks
Now an answer for Simulink, this basically implements the same as M=magic(5);M(:,2)=1:5

When using a multiple-output matlab function, do i need to callback all variables?

When using a multiple-output matlab function, do i need to callback all variables? or can I just take the first two variables? (if so..is it not recommended?)
lets say in function.m
[a, b, c] = function( )
in main.m
[var1, var2] = function;
When calling (almost) any function in matlab you can request fewer outputs than it specifies. So, yes the example you give should work perfectly fine.
There are some clever things you can do with this, such as using nargout within a function to see how many output arguments have been requested and only calculating the values that have been requested as an optimisation trick.
It depends on the definition of the function, and exactly which of the outputs you want to get.
Not all the function allow to do it, you can find all the options for each function in the beginning of the help documentation on the specific function.
If you want only the 2nd, or 3rd outputs, and you want also to save the computation-time of the results that does not interesting, you can use ~ option, like this (for versions 2009b and later):
[~, var1, var2]=function
Many functions allow for options to passed that change how the function behaves. I used/wrote various numerical solving functions a bit and one that nice amount of option, for instance is the LSMR function(s).
Otherwise, if you can manipulate the original either introduce an input(s) to do so before or at the end with an inline subroutine to generate the outputs you want.
Or if you can't it will return as either a cell array or a vector and you can pass an anonymous function to generate the desired outputs that way.
Really, can be done many ways. Very contextual.

Dynamic variables matlab

How can I access to dynamic variables in Matlab? I search for similar question but I didn't find.
Example (simplified):
for i=1:1
aux3=(i-1)*50;
delay_64_264(1,i) = mean(delay_64_264_', num2str(aux3), ' (:,3)*100;
end
What I want to do is mean of column 3 from variable delay_64_264_0.
Anyone can help me?
Thank you very much
You can use eval().
But I recommend not doing this at all. Use a multidimensional array, rather than lots of variables with slightly different names.
To follow on from Oli's suggestions, see this piece of the MATLAB FAQ:
http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
which shows how to use structures and cell arrays as an alternative to eval.