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!