Sandwiching "num2str" in between file-naming loop.
이전 댓글 표시
I'm trying to create an automated loop to extract data from .txt files that are generated from a different script. <NoNodes> is describing for a variable such that NoNodes = [16, 36, 64, 100, 144 . . . (n-2)^2, n^2]. Just squaring even integers starting at 4.
The real issue I am having is solving for <myfilename(i)>. I've put a code break at line that defines <Stress> so I can see the affects. It combines strings in a way that I do not understand and generates numbers I do not know how they've been solved.
I.e. for i = 1, this is the string output I got:
ans =
"CombinedStresses.Periodic.N49CombinedStresses.Periodic.N54"
Any idea's for the code below?
N = 100;
NoNodes = (4:2:N).^2
A = "CombinedStresses.Periodic.N%u";
B = ".Z5.Gaussian.Data.10_08_2020.Trial.1.txt";
for i = 1:length(NoNodes);
myfilename(i) = sprintf(A, num2str(NoNodes(i)), B);
filename = fullfile('D:\University\Fall 2020\Class\HW3\Raw Data\Stresses', myfilename);
Stress = readtable(myfilename(i));
end
댓글 수: 1
Walter Roberson
2020년 10월 9일
no it doesn't. The num2str gives '16' which is char(49 54) and the %u converts the char(49) to '49'. The vector is not finished outputting so it repeats the format and converts the char(54) to '54'. So you end up with like 'PQR49PQR54'
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!