Error: Unable to perform assignment because the left and right sides have a different number of elements.

1 visualizzazione (ultimi 30 giorni)
Here's my code:
r = input("Inserta el radio:");
densidad = 1.225;
vol = (4/3)*pi*(r^3);
dt = 0.002;
m = 0.000000796
g = 9.8;
A = 0.00008;
%constantes:
b = 0.000115454
%metodo de euler:
yinicial = 0;
yfinal = 1;
y = yinicial : dt : yfinal;
N = length(y);
x(1) = 0
x = zeros(1,N)
vf = zeros(1,N)
vf = input("Ingresa velocidad:")
vf(1) = vf
for a = 1: (N-1)
vf(a+1) = ((-g)+((p-A*a)*(vol*g)/m)-((b*vf)/m))*dt+vf;
end
for a = 1: (N-1)
p(a+1) = p(a)+(dt*vf(a))
end
hold on
plot(y,vf,'r')
title("Velocidad vs tiempo")
plot(y,p, 'b')
title("Posicion vs tiempo")

Risposte (1)

KSSV
KSSV il 20 Ott 2020
Modificato: KSSV il 20 Ott 2020
for a = 1: (N-1)
vf(a+1) = ((-g)+((p-A*a)*(vol*g)/m)-((b*vf(a))/m))*dt+vf(a);
end
  4 Commenti
Alejandra Caballero
Alejandra Caballero il 20 Ott 2020
I tried it and it showed me the previous error ("Unable to perform assignment because the left and right sides have a different number of elements.") Again! )):
KSSV
KSSV il 20 Ott 2020
Modificato: KSSV il 20 Ott 2020
You define all the variables...and copy the code.....I tried running it..but few variables are missing.
This error comes..when you try to store a array into a scalar.
Example:
c(1) = rand(1,2) ; % this shows error. Samething happening in your code
Check the size of
((-g)+((p-A*a)*(vol*g)/m)-((b*vf(a))/m))*dt+vf(a);
it might not be a constant.

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by