How can I create a 2-term, 1-by-1 string using sprintf?
古いコメントを表示
I am using the following code to refer to 4000x15 doubles I have in my workspace, they are named P1-17. When I use the code however, the name becomes a 1x2 char and therefore a variable itself. When I try to use it in the function that's in the loop, it does not refer to the 4000x15 data at all.
Does anyone know how to fix this or do it in another way? I have tried a lot of things but I can't figure this one out.
for j = 1:1:17
filename = (sprintf('%s%d','P',j)) ;
[sgmean] = DataPrep(filename) ;
end
3 件のコメント
Stephen23
2022 年 5 月 5 日
Acessing variable names dynamically is one way that beginners force themselves into writing slow, complex, inefficient, obfuscated, buggy code that is hard to debug. Read this to know some reasons why:
I doubt that you wrote all of those variable names by hand, so the most important question is: how did you get all of those variables into the workspace? My guess is that you imported them somehow, in which case that would be the correct place to fix this badly-designed data. For example, you should always LOAD into an output variable:
S = load(..)
Stephen23
2022 年 5 月 9 日
"but use one of the alternatives in the documentation you attached?"
You don't need to guess, I already told you which alternative to use: LOAD into an output variable.
Yasmin Ben Azouz
2022 年 5 月 9 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!