Hello everybody,
I have a set of arrays inside the workspace whose names are like the followings: Data1_Asc, Data1_BML, Data2_Asc, Data2_BML... Datan_Asc,Datam_BML.
I want to divide these variables into n different .mat files where each variable inside everyone of these files would be named as:
Data1_Asc, Data1_BML.
Any suggestion?
Thanks

댓글 수: 1

Stephen23
Stephen23 2022년 4월 19일
편집: Stephen23 2022년 4월 19일
"Indexing inside variables name"
Forcing pseudo-indices into variable names is much less efficient than using actual indices.
Accessing numbered variable names forces you into writing slow, complex, inefficient, fragile, obfuscated code.
You did not tell us the most important information: how did you get all of those variables into the workspace?

댓글을 달려면 로그인하십시오.

 채택된 답변

Stephen23
Stephen23 2022년 4월 19일
편집: Stephen23 2022년 4월 19일

1 개 추천

for k = 1:N
v1 = sprintf('Data%u_Asc',k);
v2 = sprintf('Data%u_BML',k);
fn = sprintf('File%u.mat',k);
save(fn,v1,v2)
end
Better data design would use exactly the same variable names in every file.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Variables에 대해 자세히 알아보기

제품

릴리스

R2022a

질문:

2022년 4월 19일

편집:

2022년 4월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by