Loop different variables from workspace
显示 更早的评论
num = 1; -------> 475
current_file = Test_1; -----------------> test_475 (Table of name 'Test_1' in workspace)
rate = height(current_file);
for i=1:rate
rel = current_file.S;
vel = current_file.E;
time = current_file.t;
Target_v{i,1} = rel(i) + vel(i);
if i == rate
T = array2table(Target_v);
C = [current_file(:,1:3) T current_file(:,4:45)]
eval(['Dataset_' num2str(num) '= C']);
Target_v= [ ];
end
end
I want to load multiple variables that are in workspace in a for loop add a column to each one of them and save them with another name or export them to excel. How can I do this?
4 个评论
Go back and make a single variable, instead of many, to hold the information.
Stephen23
2019-12-16
"I want to load multiple variables that are in workspace in a for loop..."
If they are already in the workspace then they have already been loaded (unless you wrote out all of those names by hand), so most likely the best choice would be to simplify your code and load the data into one array (e.g. a cell array, a structure, a table, etc.).
Note that having many numbered variables is a sign of badly designed data.
"...add a column to each one of them and save them with another name or export them to excel."
Easy with basic indexing into one variable.
Mariana
2019-12-16
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Tables 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!