vectors must be the same length
Afficher commentaires plus anciens
I'm trying to create a graph but the code is getting teh error above.
x = [3.15647 4.15647 5.15647 6.15647 7.15647]; y = [4.15280 5.88409 7.81539 5.24301 4.09266];
plot(x,y,'o'); hold on
xa = linspace(0, 0.5, 10) ya = 4.15+(1.73.*(x-3.15))+(0.1.*(x-3.15).*(x-4.15)); plot(xa,ya,'-');
Réponses (2)
Star Strider
le 27 Jan 2018
You probably want to use ‘xa’ rather than ‘x’ in your ‘ya’ calculation:
ya = 4.15+(1.73.*(xa-3.15))+(0.1.*(xa-3.15).*(xa-4.15));
Rik
le 27 Jan 2018
You used the variable x in your definition of ya, which results in xa being length 10 and ya being length 5.
x = [3.15647 4.15647 5.15647 6.15647 7.15647];
y = [4.15280 5.88409 7.81539 5.24301 4.09266];
xa = linspace(0, 0.5, 10);
ya = 4.15+(1.73.*(xa-3.15))+(0.1.*(xa-3.15).*(xa-4.15));
plot(x,y,'o',xa,ya,'-')
(Also, next time, select your code and push the {}Code button to correctly format your code)
Catégories
En savoir plus sur Discrete Data Plots 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!