Plotting from a Loop - "Error: This statement is incomplete"
古いコメントを表示
I'm trying to plot a tier of my structural array with the following code:
for site = 1:19
plot((eval(sprintf('TVC_ForPointCLM.SMP.Profiles.%.force'))),(eval(sprintf('TVC_ForPointCLM.SMP.Profiles.%.depth_smp'))));
hold on
end
hold off
xlabel('Force (N)')
ylabel ('Distance from SMP initialisation (mm)')
When I run this, I get a message saying "Error: This statement is incomplete." about the 2nd line of the code. I've double checked the parenthesis match, so that's not it, but I'm not sure what else would cause this error.
TVC_ForPointCLM is the structural array, and then there are 19 profiles where % is subsituted into the variable name.
4 件のコメント
KSSV
2020 年 4 月 20 日
Using eval is a bad idea.....what made you to use eval?
Victoria Dutch
2020 年 4 月 20 日
The more efficient and robust method is to use dynamic fieldnames:
Avoiding eval would help you to debug your code and avoid basic errors in your code.
Victoria Dutch
2020 年 4 月 20 日
採用された回答
その他の回答 (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!