How can I do to avoid using eval?
显示 更早的评论
Hi! I'm modifying a code created with Matlab but I have a problem: I'd like to avoid using the eval function and at the same time create arrays that contain a variable number of elements.
For example, in this part of code
num_int = 3;
for k = 1 : num_int
eval(['m = length(I',num2str(k),')'])
for i = 1 : m
if count_vector(k) == 0
eval(['ydata_low_',num2str(k),'(i,:) = [I',num2str(k),'_0(i) I',num2str(k),'_1(i) I',num2str(k),'_2(i) I',num2str(k),'_3(i) I',num2str(k),'_4(i)]']);
eval(['ydata_high_',num2str(k),'(i,:) = [I',num2str(k),'_5(i) I',num2str(k),'_6(i) I',num2str(k),'_7(i) I',num2str(k),'_8(i)]']);
end
end
I should create ydata_low and ydata_high, in function of k (that is num_int and is worth is 3).
In short, six arrays should be created: ydata_low_1, ydata_low_2, ydata_low_3, ydata_high_1, ydata_high_2 and ydata_high_3. The program already creates the variables to be introduced into the matrices (see attachment). I'd also like that variables from I_0 to I_4 are inserted in data_low and the variables from I_5 to I_8 are inserted in data_high.
Thank you!!
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!