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

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

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.

Help writing a recurrence relation in MATLAB

I have this recurrence relation which is defined as:
$x_{j+1}-2x_j+x_{j-1}=1$
$j=1,2,...$
My task is to write two MATLAB functions, the first one should generate a fixed number $n$ of elements of the sequence $x_j$. The only user input should be $n$.
The second function should compute terms up until $x_j > x_{max}$ and then stop. The value $x_{max}$ should be the input.
In both cases, I need to provide two initial conditions chosen at random in $(0, 1)$ in the code.
Can anyone help me here?
EDIT: I can't seem to add comments - sorry I didn't realise this was the wrong area, can someone delete this question?
Your sequence is polynomial.
This is your first function:
function res=u(n)
res=(0:n).^2/2+interp1(0:1,rand(1,2)-[0 1],0:n,'linear')
The second function should solve the second degree polynomial and then use u(ceil(n_root))

Summing the image matrix matlab

I am new to matlab . Can someone please tell me whats wrong with this snippet for summing the 3-D array of image.Its showing error in 3rd line and I am unable to debug it.
x=imread('test.jpg');
imshow(x);
sumdiff=sum(sum(sum(testArr2, 3),2),1)
The only thing that strikes me as obviously wrong is that you are summing over the values in a variable called testArr2 but have the image pixel data in a variable called x. Where does testArr2 get defined and populated with data ?
While Mark had probably answered the question, I wanted to add that the easiest way to sum over the entire array is probably using the colon syntax:
sum_all = sum(x(:))
Also note that imread usually returns an array of integers (uint8 for standard jpeg images). Not all mathematical operations are allowed when using this type of arrays - and sometimes using im2double is necessary.

How to use find() method in simulink?

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.

Matlab: Element by element selection without loops

I have one big matrix of for example 3000X300. And I need to select each element and do several calculations with it. I looked into using the array fun function but because the output of my program is not one value this is not possible.
It works fine now with the loops but it has to preform much faster, so i want to remove the for loop.
Maybe i'll try to be more specific: Each value of the big matrix has to give me an answer of 4 different matrices with the size of 4X6020..
So i don't know if this is possible making this vectorized...
Maybe somebody has other suggestions to make it faster?
greetings,
You can use arrayfun and set uniformoutput to false. See here.