Unable to perform assignment because the left and right sides have a different number of elements.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I am trying to calculate all values of velocity and displacement for the times between 0 and 20 in increments of 0.01. Im struggling to add on the last value of velocity and displacement as i need to be able to use the previous iteration values where i have tried doing this using the variable 'i'. I think the problem is due to the different sizes of matrices. Im quite new to coding so any help would be appreciated, thanks.
1 Commento
Katie
il 20 Gen 2021
Can you please attach or copy your code so we can see how you're setting it up? Thanks!
Risposte (1)
Walter Roberson
il 20 Gen 2021
dt = 0.01;
i0 = 1;
i(1) = i0;
i = (1:dt:21);
Note that overwrites all of i
It is not recommended to use i as a variable name, as it can lead to confusion because i is used as sqrt(-1)
i will be a vector of length 2001 I think.
for t = [0:0.01:20.0]
v(i+1) = a*0.01 + a(i)*t;
You ask to index a(i) but a appears to be a scalar at that point, and i contains non-integer values that are not valid as indices.
You also multiply all of a by 0.01 so if a is a non-scalar (due to code you did not show us) then it might not be the same size as a(i) .
If somehow (that is, if the code you posted is not the code that generated the error) i were a scalar integer at that point but a were a vector, then v(i+1) would hypothetically designate a scalar, but a*0.01 would be a vector and you would be trying to store a vector result into a scalar field.
... But the code you posted would have failed before that, failing when trying to index a at the non-integer i
3 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!