필터 지우기
필터 지우기

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 CenterFile Exchange에서 Whos에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by