Passing variables in string under for loop.

6 ビュー (過去 30 日間)
Paramjit Yadav
Paramjit Yadav 2021 年 8 月 11 日
編集済み: the cyclist 2021 年 8 月 11 日
Hello,
I am trying to run the below code. Here I am passing the string with i and j as variable but it is not taking i and j as variable and showing errors.
Can some please help by saying how to do indexing with in a string and pass the values of i and j in the string in for loop as variable.
for j = 1:12
for i = 1:12
lt.Cmd('AddPickup "SPLINEPATCH_LENS_SURFACE[LensRearSurface].ZValueAt[i][j]"')
end
end
Thank you so much for reading my querry.
Regards
Paramjit

回答 (1 件)

the cyclist
the cyclist 2021 年 8 月 11 日
編集済み: the cyclist 2021 年 8 月 11 日
You need to convert the numeric values in the loops into strings. Here is how to construct the string to pass into lt.Cmd:
i = 1; % Using just a couple specific values, instead of the whole loop, just to illustrate one case
j = 2;
strcat('AddPickup "SPLINEPATCH_LENS_SURFACE[LensRearSurface].ZValueAt[',num2str(i),'][',num2str(j),']"') % You would pass this string into lt.Cmd
ans = 'AddPickup "SPLINEPATCH_LENS_SURFACE[LensRearSurface].ZValueAt[1][2]"'
The idea here is that I am creating strings out of i and j, and then concatenating all of the strings together into the one long string you need.

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by