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

采纳的回答

Benjamin Thompson
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 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by