- 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
6 ビュー (過去 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!