using a variable to call another variable

조회 수: 2 (최근 30일)
Irshad Qureshi
Irshad Qureshi 2022년 9월 16일
댓글: Irshad Qureshi 2022년 9월 16일
Hello all,
After doing analysis in some other software I get text files namely Eigen_1.txt, Eigen_2.txt.......Eigen_k.txt and each file is 4x4 matrix. I want to read each file, get the (1,3) value and assign it to variable T1_1, T1_2.......T1,k and then use this value to get omega1_1 and so on. I have used eval command which works fine, but is there any other way to solve this without using eval command.
for n = 1:k
temp = readmatrix(strcat('.\Results\Eigen_',num2str(n),'.txt'),'delimiter',' ');
eval(['T1_',num2str(n),'=temp(1,3)']);
eval(['omega1_',num2str(n),' = 6.2832/T1_',num2str(n),]);
end
  댓글 수: 4
Irshad Qureshi
Irshad Qureshi 2022년 9월 16일
thanks, Stephen.

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

채택된 답변

Chunru
Chunru 2022년 9월 16일
편집: Chunru 2022년 9월 16일
T1 = zeros(k, 1); % use array instead of T1_, T1_2, ...
omega1 = zeros(k, 1);
for n = 1:k
temp = readmatrix(strcat('.\Results\Eigen_',num2str(n),'.txt'),'delimiter',' ');
% eval(['T1_',num2str(n),'=temp(1,3)']);
% eval(['omega1_',num2str(n),' = 6.2832/T1_',num2str(n),]);
T1(n) = temp(1, 3);
omega1(n) = 2*pi/T1(n);
end
  댓글 수: 1
Irshad Qureshi
Irshad Qureshi 2022년 9월 16일
Thanks. Its working and its much easier also.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by