필터 지우기
필터 지우기

How do I assign different variable names for different files?

조회 수: 8 (최근 30일)
Prasenjit Dewanjee
Prasenjit Dewanjee 2022년 10월 25일
댓글: Stephen23 2022년 10월 30일
Hi! I have 10 csv files (100*10 size) in one directory. I want read all the files and convert them to tables. I want to assign different variable name for each of the table. For example: data1= file1, data2=file2 and so on. How do I do that? I am a hard time creating dynamic variables like 'data1' in a loop to assign the file data to them. Any help will be much appreciated!

답변 (1개)

David Hill
David Hill 2022년 10월 25일
Something like this should work. It would be better to place all the files into a single matrix and use indexing.
for i=1:10
a=sprintf('file%d.csv',i);
eval(['data' num2str(i) '= readmatrix(a);']);
end
  댓글 수: 1
Stephen23
Stephen23 2022년 10월 30일
"It would be better to place all the files into a single matrix and use indexing."
Which is also exactly what the MATLAB documentation shows:

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

카테고리

Help CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by