Converting 1D array into a constant (taking the last value of the array)

4 views (last 30 days)
I have a embbed matlab function(EMB1) in front that does the convergence so the last value of the array is the converged value. Currently, the rest of the model will take the non-converged as it is at their time step. What I wanted to do is to take the last value (i.e. the last time step) of the array and apply it to the rest of the model(at all time step).
I have tried transposing the array into row vector(?)(i.e. into a single row and 400 column) then using another embbed matlab function(EMB2) to select the last value to continue but somehow the transpose block is not working as out.simout does not show it on the row vector and subsequently got hit with the 'index expression out of bounds' error. Below shows the matlab script for EMB2, where 400 is the last value in the array:
function y = fcn(u)
u=u(400);
y=u;
end
From what I have trial and error, the term 400 in the bracket is for the 400th column and not the 400th row which is why i tried (and failed) to transpose the 1D array. Please advise on the next step/suitable block to use. I have been stuck on this for 2 days now.

Answers (1)

Image Analyst
Image Analyst on 7 Mar 2020
Not sure why
function y = fcn(u)
y = u(end);
doesn't work. It seems to work for me, for both vectors and multidimensional arrays.
What are you passing in for u (number of rows and columns), and which element do you want returned?
  5 Comments
Image Analyst
Image Analyst on 8 Mar 2020
Sorry, but I don't have the MATLAB Coder Toolbox, or whatever is required to make embedded (in silicon) modules. I also don't know what simout is. If that's Simulink, I don't have Simulink.

Sign in to comment.

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!