Load data and store in workspace in individual variables
1 次查看(过去 30 天)
显示 更早的评论
Hello, I'm trying to load data and that load data storing with different names in the workspace to use them later. So far I've done the following code:
for x = (0.75:0.75:19.5)
QTableS = 'Episodes%dQTableMatrixSetPoint%d.mat';
QTable_x = 'QTable_%d.mat';
A1 = 50;
A2 = x*100;
%%% Name data to load and data to store in workspace
str_QTable = sprintf(QTableS,A1,A2);
str_QTable_x = sprintf(QTableS,A2);
% load data and store in workspace
str_QTable_x = load(str_QTable);
str_QTable_x = str_QTable_x.QTable_Matrix;
end
So far it correctly loads the data from each of the store .mat files. But when storing the data to the workspace it overlaps each loop and I only have the last file loaded. What I want is to create a new variable with each loaded data in the workspace for each loaded file.
1 个评论
Stephen23
2023-11-4
"What I want is to create a new variable with each loaded data in the workspace for each loaded file."
A much better approach is to use indexing, just as the MATLAB documentation shows:
回答(1 个)
Steven Lord
2023-11-3
Can you dynamically create variables with numbered names like x1, x2, x3, etc.? Yes.
Should you do this? The general consensus is no. That Answers post explains why this is generally discouraged and offers several alternative approaches.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!