Min function will not accept "linear" option
Show older comments
Hello, I have the data attached in the .mat file below labeled "troubleshoot."
Background:
Essentially there is a column vector W0_guess, 46 entries long, and a 46x2 matrix, W_0_calc. Each row of W_0_calc is related to the corresponding row in W0_guess, and the two columns in W_0_calc are from different initial conditions. Both matrices have symunits of lbf.
The goal of this code is to find where each column of W_0_calc is closest to the corresponding value in W0_guess. To do so, I subtracted W0_guess from each column of W_0_calc, and took the absolute value of that matrix. Then I want to find the linear index of the minimum value of each column of that new "findMin" matrix.
When I try to use that data in the following code, the min function throws an error saying "too many input arguments."
z = symunit;
findMin = (abs((W_0_calc - W0_guess)/z.lbf));
[~,idx] = min(findMin,[],1,'linear')
idx = idx';
Optimal_Weight = vpa([W0_guess(idx) W_0_calc(idx)],5)
I want the linear index so that I can construct the Optimal_Weight matrix, which in each row has corresponding values of W0_guess and W_0_calc.
I originally had the contents of the variable "findMin" directly inside the min function, I just wanted it to be easier to find my own errors.
I cannot figure out why this code does not work, especially when the following code from Matlab's help documentation is similar.
A = [1 2 3; 4 5 6]
[M,I] = min(A,[],1,'linear') % The 1 here was originally a 2 in the documentation. I wanted to parse the columns.
minvals = A(I)
Thank you for the help. I am using R2020a.
Accepted Answer
More Answers (0)
Categories
Find more on Elementary Math in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!