You are watching: Unable to perform assignment because the left and right sides have a different number of elements.
A = 1250; Q = 450; t = (0:0.5:10);y(1) = 0;for i = 1:length(t) y(i+1) = y(i) + <(3*(Q/A).*sind(t).^2)-(Q/A)>.*0.5;enddisplay(y);
Inside the for loop, you assign an expression (the RHS) to an array (the LHS). y(i) is a 1x1 array, and the RHS has the same dimensions as t (1x21). You cannot assign 21 values to an array that can only hold one. To repair, I"d suggest preallocating y, with the line
y = zeros(numel(t), numel(t))or, what I think you probably intended, only call one element of t at a time
y(i+1) = y(i) + <(3*(Q/A).*sind(t(i)).^2)-(Q/A)>.*0.5;As an aside, it is bad practice to use i as a variable as it already has a built-in value in Matlab. For loop indices I usually use ii, jj or k.
Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!
But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.
See more: Phase Diagrams For W At -70 ∘C And 5.2 Atm, Carbon Dioxide Is In Which Phase?
To learn more, see our tips on writing great answers.
Post Your Answer Dismap
Not the answer you're looking for? Browse other questions tagged matlab or ask your own question.
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side. What does this mean?
Unable to perform assignment because the left and right sides have a different number of elements. MATLAB ERROR
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2021.9.22.40267