Min function will not accept "linear" option

1 vue (au cours des 30 derniers jours)
Corrado Mazzarelli
Corrado Mazzarelli le 26 Fév 2021
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.

Réponse acceptée

Walter Roberson
Walter Roberson le 26 Fév 2021
z = symunit;
symunit involves Symbolic Toolbox
findMin = (abs((W_0_calc - W0_guess)/z.lbf));
You pull out a unit there and divide by it. Regardless of whether the original expression had a unit (that you are effectively removing) or if you are just wanting to add a unit here, you can be sure that the result, findMin, will be symbolic.
[~,idx] = min(findMin,[],1,'linear')
You are invoking min() on a symbolic object. Symbolic min() does not support 'linear'
If the division by z.lbf was not attempting to remove all units, then you would have the additional problem that min() of symbolic expressions can only work if there are no unbound variables in the expression... unbound variables such as symbolic units.
  1 commentaire
Corrado Mazzarelli
Corrado Mazzarelli le 26 Fév 2021
Thank you good sir. Converting to double solved that issue for me.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Elementary Math dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by