How can I make the "number of elements" the same?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
w2=2*pi;
TH2=0;
t=2
a2=0.5*t;
L2=50;
L3=150;
for n=1:2:360
TH3(n)=acosd((L2*cosd(TH2))/L3)
d1(n)=((L2*sind(TH2))-(L3*sind(TH3)))
w3(n)=(L2*w2*sind(TH2))/L3*sind(TH3)
d2(n)=(L2*w2*cosd(TH2))-L3*w3*cosd(TH3)
a3(n)=((-L3*w3^2*cosd(TH3))+(L2*a2*sind(TH2)))+(L2*w2^2*cosd(TH2))/L3*sind(TH3)
d3(n)=(L2*a2*cosd(TH2))-(L2*w2^2*sind(TH2))-(L3*a3*cosd(TH3))+(L3*w3^2*sind(TH3))
end
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in DynamicsPistonProject (line 12)
d1(n)=((L2*sind(TH2))-(L3*sind(TH3)))
I've learned that this error message occurs because you cannot equate matrices with different dimensions. However, I do not know how to fix this error, because neither matrices are previously defined. I've tried deleting the intended line, but the error still occurs for the next line and so forth.
0 comentarios
Respuestas (1)
James Tursa
el 23 de Jun. de 2016
Editada: James Tursa
el 23 de Jun. de 2016
Here you are building up TH3 elements in a loop, so TH3 will be a vector:
TH3(n)=acosd((L2*cosd(TH2))/L3)
And here you make an assignment.
d1(n)=((L2*sind(TH2))-(L3*sind(TH3)))
On the rhs is TH3, a vector, so the rhs will evaluate to be a vector. But the lhs is just a single element, d1(n). You can't assign a vector to a single element. So you need to scrub this code and fix up all of these cases. What do you really want happening on the rhs? Maybe you didn't want TH3 to be a vector, but a scalar, in which case maybe this would do what you really want:
TH3 = acosd((L2*cosd(TH2))/L3) % <-- Got rid of the (n) index on lhs
Also, you should consider putting semi-colons after each of those calculation lines to suppress the intermediate output going to the screen.
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!