it is not working.
信息
此问题已关闭。 请重新打开它进行编辑或回答。
显示 更早的评论
%%%%%%%%%%%%%% acceleration matrix %%%%%%%%%%%%%%
for g=1:1:10
for i=1:ne
Ecc=eval(['Ee',num2str(i)]);
if (i<166)&&(i>420)
ug=[0.3*Ug(g,2);Ug(g,2);0;Ecc*Ug(g,2);0.3*Ug(g,2);Ug(g,2);0;Ecc*Ug(g,2)];
if (i>165)&&(i<421)
ug=[Ug(g,2);0.3*Ug(g,2);0;Ecc*Ug(g,2);Ug(g,2);0.3*Ug(g,2);0;Ecc*Ug(g,2)];
eval(['f',num2str(i),'=MGf.ug']);
t=eval(['T',num2str(i)]);
ff=eval(['f',num2str(i),'l']);%Calling local acceleration matrix
eval(['f',num2str(i),'g','=transpose(t).*ff.*t']);%Evaluation acceleration matrix in global coordinate system
end
end
end
end
2 个评论
Stephen23
2020-1-25
"it is not working."
... because it is badly wrritten, badly aligned, badly designed code.
Sorry, but that code should be thrown away and replaced with simpler, more efficient code that actually uses arrays and indexing properly. It is a complete waste of MATLAB to use eval for every trivial operation and for accessing data. That code calls eval seven times, on nearly half of the code lines, which is very bad design makes the code slow, complex, obfuscated, buggy, and very difficult to debug, and is exactly why the MATLAB documentation and all experienced users recommend avoiding writing such pointlessly slow, complex, buggy code like this:
You need to learn how to use arrays.
You need to learn how to use indexing.
You need to avoid eval for such trivial code like this.
Start by doing the introductory tutorials, which show how to create and access data in arrays (and don't use eval at all):
John D'Errico
2020-1-25
@pramod kumar:
Please learn to use comments instead of answers if you are not providing an answer. Answer movect to a comment:
"please help how to correct it."
回答(1 个)
Chaudhary P Patel
2020-1-27
0 个投票
9 个评论
Walter Roberson
2020-1-27
What is your revised code?
Chaudhary P Patel
2020-1-27
Chaudhary P Patel
2020-1-27
Walter Roberson
2020-1-27
You said that you corrected the code but it is still full of eval()
None of the regular volunteers is likely to take the question seriously until the code is rewritten so that it does not use eval.
Chaudhary P Patel
2020-1-27
Walter Roberson
2020-1-27
The problem with your code is that it uses eval. It will never work correctly unless you get rid of all the eval.
Chaudhary P Patel
2020-1-27
Chaudhary P Patel
2020-1-27
"...tell me one thing how to assemble the global force vector."
Write the code without eval.
Once you do that, then you can trivially use indexing to allocate to your "global force vector" (and also use all of the standard, inbuilt code helping tools to help debug your code). For as long as you use eval like that, your code will be slow, complex, buggy, hard to debug, and will continue to waste your time.
此问题已关闭。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!