フィルターのクリア

Load data and store in workspace in individual variables

2 ビュー (過去 30 日間)
Ander Alberro
Ander Alberro 2023 年 11 月 3 日
コメント済み: Stephen23 2023 年 11 月 4 日
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
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
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.

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by