=polyfit function give error in matlab app designer app
Afficher commentaires plus anciens
p = polyfit(x, y, 1); with arrays shown below.
When executed in the app, error is given :
"Error using polyfit (line 44)
X and Y vectors must be the same size."

When the same poly fit function is executed from the command window in matlab ( and putting the variables in workspace). the function works as expected.
For extra insight, the x and y variables are concatinated before using the poly function with the following code:
where xneg is columns 1 - 7(backwards) and yneg is 1-7 ( was originaly part of a larger array)
x = [flip(xneg); xpos];
y = [yneg(1:7) ypos];
Any help or insight would be greatly appriciated!
Réponse acceptée
Plus de réponses (1)
Can you show us exactly how x and y are defined in your App Designer code? If you're retrieving them from a property of an edit box, are you using an EditField, a NumericEditField, or some other component? In particular what are the class of the x and y inputs with which you're calling polyfit?
x1 = [1 2 3];
class(x1)
x2 = '[1 2 3]';
class(x2)
y1 = [-2 -5 -9];
whos x1 y1 % same number of elements in x1 and y1
p1 = polyfit(x1, y1, 1) % works
y2 = '[-2 -5 -9]';
whos x2 y2 % different sizes because different number of characters
p1 = polyfit(x2, y2, 1) % does not work
If my suspicion is correct, that your x and y are text (char or string), you may want to switch to a NumericEditField.
1 commentaire
collin bannister
le 20 Août 2024
Catégories
En savoir plus sur Data Type Identification dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
