How can i use two variables while using eval command
3 次查看(过去 30 天)
显示 更早的评论
Sir/ Madam
I wrote this command for running for 100 time steps under for each n=5; when i wrote it like this
eval(['FSS',num2str(n),'=k_t*Uy(:,1)']);
and the result is coming like FSS1 as a string n.
but time step is not comming i want to involve time step also.
Please help me.
thanks.
22 个评论
Walter Roberson
2022-6-5
Flag(n)=
are you going to use Flag after the loop? If not then do not bother to index Flag
else
Utt(:,i+1)=Utt(:,i+1);
f_S(:,i+1)=f_s(:,i+1);
sequences like that which copy data to itself just confuse the coding. If data is already stored where it belongs then just leave it there instead of copying it to itself
Stephen23
2022-6-6
"Here i am facing the problem for calling the i value. while i am calling it only taking Utt5 value."
There is no variable named Utt5. But assuming that you actually mean that your code ignores all of the n iterations and only keeps the last one, then yes, because that is what you wrote your code to do. Your code (apparently, from my quick review) make no attempt to store the results of the n iterations, thus only the last one will appear in the workspace. You told MATLAB to keep overwriting the results of the n iterations, so that is what it does.
The solution to that is to use indexing (your approach using dynamic variable names would not actually help you, just make your code even more complex, and should be avoided). Reducing code clutter, as Jan suggested, would help too.
Either this is a mistake or a misleading way of distinguishing variables:
f_S(:,i+1)=f_s(:,i+1);
% ^ ^
回答(1 个)
Jan
2022-6-4
If you really need different arrays, because the contents have different sizes, use a cell array:
Utt = cell(10, 5);
for i = 1:10
Utt{i, 1} = [zeros(nodof,1); utdelt(1:nodof, i+1)];
for n = 2:5
d1 = 1 + (n-2) * nodof;
d2 = 6 + (n-2) * nodof;
Utt{i, n} = utdelt(d1:d2, i+1);
end
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Signal Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!