Trying to save the outputs of a for loop
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi, i am trying to save the different values of the for loop for sigmar1_1 so that i can then plot it. The problem is that i am getting the following error:
'Unable to perform assignment because the indices on the left side are not compatible with the size of the right
side.'
My understanding is that its from the way im creating my zeros array. Thanks in advance for the help.
ri=20;
ro=60;
i=0.03;
E=200000;
v=0.3;
R1=58;
syms p
%e=zeros();
for r=20:40
b1_1=ri^2;
a1_1=(1-b1_1/r^2);
b2_1=ro^2;
a2_1=(1-b2_1/r^2);
A1=(a1_1^-1)-p;
B1=A1*ri^2;
sigmar1=A1*(1-b1_1/r^2);
sigmat1=A1*(1+b1_1/r^2);
inter1_1=sigmat1-v*sigmar1;
inter1=inter1_1/E*r;
A2=(a2_1^-1)-p;
B2=A2*ro^2;
sigmar2=A2*(1-b2_1/r^2);
sigmat2=A2*(1+b2_1/r^2);
inter2_1=sigmat2-v*sigmar2;
inter2=inter2_1/E*r;
eqn=inter1+inter2==i
S=solve(eqn,p)
A1_2=(a1_1^-1)-S;
A2_2=(a2_1^-1)-S;
sigmar1_1=A1_2*(1-b1_1/r^2);
e=zeros(length(sigmar1_1));
e(r)=sigmar1_1
end
댓글 수: 0
채택된 답변
Benjamin Thompson
2022년 10월 10일
The first value of R in the loop is 20, and you are reassigning/overwriting zeros to e on every pass through the loop. Before the for loop, create e:
e = zeros(21,1); % For vector of 21 rows, 1 column
Then assign to the correct index in e at the end of the loop:
e(r - 19) = sigmar1_1
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!