Read in matrix for multiple steps while changing string
2 次查看(过去 30 天)
显示 更早的评论
Hi, I want to read in multiple temperature files at different time steps. For instance I have array:
time = [0, 10, 20];
And I need to read in:
temp0 = "temperature_0.txt"
temp1 = "temperature_10.txt"
temp2 = "temperature_20.txt"
So I can compile them all into:
temp = [temp0;temp1;temp2]
How can I handle changing the string names "temp0" and "temperature_0.txt" based on the value in time? I know I will have a for loop such as follows, but I am unsure of how to make the variable input into the name as a string
for k = 1:length(time)
...
end
1 个评论
采纳的回答
Steven Lord
2023-5-24
time = [0, 10, 20];
files = "temperature_" + time + ".txt"
Now you could iterate over the elements of the files string array.
3 个评论
Steven Lord
2023-5-24
If the only digits in the names are in the numbers you want to extract, use digitsPattern to extract that data from the string array.
time = [0, 10, 20];
files = "temperature_" + time + ".txt"
numbersAsText = extract(files, digitsPattern)
numbers = double(numbersAsText)
isequal(time, numbers)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!