Help me with this error!
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mobasher Hossain
le 14 Mar 2015
Commenté : Mobasher Hossain
le 14 Mar 2015
I'm trying to plot x vs y,saving the values in arrays:
clear all;
l = 0.1;
for index = 1:30;
x(index) = (index-1)*0.1;
y(index) = pi*(x.^2 + 1).^2 *l;
end
%PLOT x VERSUS y
plot(x,y);
xlabel('x');
ylabel('pi*((x^2+1)^2)*l');
But I'm getting this error: In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in problem_02 (line 8) y(index) = pi*(x.^2 + 1).^2 *l;
0 commentaires
Réponse acceptée
Roger Stafford
le 14 Mar 2015
Instead of:
y(index) = pi*(x.^2 + 1).^2 *l;
you should write:
y(index) = pi*(x(index)^2 + 1)^2 *l;
Either that or else you should do:
y = pi*(x.^2 + 1).^2 *l;
after you exit the for-loop.
As it stands you have a scalar on one side of the equation and a vector on the other side in the original
y(index) = pi*(x.^2 + 1).^2 *l;
That is what matlab is unhappy about.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!