=polyfit function give error in matlab app designer app
Mostra commenti meno recenti
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!
Risposta accettata
Più risposte (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 Commento
collin bannister
il 20 Ago 2024
Categorie
Scopri di più su Data Type Identification in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
