- Normal MATLAB does not have a function interp.
- If you put all of your data into one array arr where each column is one data set, then this would be trivial with just one interp1 call.
- dynamically accessing variable names is one way that beginners force themselves into writing slow, complex, buggy code that is hard to debug. Read this to know why:
Need to apply some tricky string interpolation for a for loop
20 次查看(过去 30 天)
显示 更早的评论
I would like to interpolate for several individual arrays. "T5_11" is one 1x24 array that I have made, and "T5_10" is another completely separate array I have made. I want the interp function to access each T5_k array from the for loop that changes the last two digits of the T5 array. How can I do a string interpolation that will change an iterator that changes the reference name of the array I'm working with? -Thanks
1 个评论
Stephen23
2018-6-26
编辑:Stephen23
2018-6-26
回答(1 个)
OCDER
2018-6-26
编辑:OCDER
2018-6-26
Read the following about why labeling variables "T5_11" and "T5_10" is extremely difficult to work with. https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval
To fix, you need to go back to your code and replace T5_k with T5{k}, where k is an integer. Then you can do what you want to do easily by summoning T5{k} instead of ["T5_" num2str(k)] (which does NOT work by the way).
EXAMPLE
T5_1 = [1 2 3 4 5] REPLACE CODE WITH ==> T5{1} = [1 2 3 4 5];
T5_1 = [6 7 8 9 10] REPLACE CODE WITH ==> T5{2} = [6 7 8 9 10];
...
% You'll have a cell array of matrix called T5 of size 1x24
for k = 1:24
interp(timeOfDay,linspace(60,90,24), T5{k});
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!