Trying to save the outputs of a for loop

1 回表示 (過去 30 日間)
IARLA O CEITINN
IARLA O CEITINN 2022 年 10 月 10 日
回答済み: Benjamin Thompson 2022 年 10 月 10 日
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 Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by