import value from text file

i have a .ini file that has variables in it, and i want to import them into matlab and assign them the same variable. the ini file looks like this:
a1=-108
a4=10
a5=0.014
a6=-0.24
etc.
so i want to be able to make a1=-108 in matlab. there are hundreds of variables so i dont want to have a formula for each.

답변 (1개)

TAB
TAB 2012년 8월 23일
편집: TAB 2012년 8월 23일

0 개 추천

fid = fopen('YourFile.txt');
data = textscan(fid,'%s','delimiter','\n');
cellfun(@eval,data{1});
fclose(fid);

댓글 수: 3

Krystina
Krystina 2012년 8월 23일
TAB, how do i assign a1=the value in the text file? the coding you suggested only calls up the whole text file when i call for it in the command window?
TAB
TAB 2012년 8월 23일
Soory, I didn't got your concern ?
Above code will created variables a1, a2...etc with values specified in the text file.
Krystina
Krystina 2012년 8월 23일
That coding is resulting in a variable A which contains ALL the content in the text file. I need to get each line assigned a variable.

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

카테고리

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

태그

질문:

2012년 8월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by