フィルターのクリア

Using Eval function with string inside it?

39 ビュー (過去 30 日間)
Jonathan
Jonathan 2011 年 10 月 9 日
編集済み: Stephen23 2019 年 6 月 19 日
Hi,
I use a lot of eval functions to run the same calculation on multiple files with similarly formatted names, and come across the following problem frequently:
for ii=1:4
var1=char(GLOBALS.Meta{ii,1});
eval([var1 '.APO_detr_Grid=griddata(' var1 '.SO_APO_detr(:,1),' var1 '.SO_APO_detr(:,2),' var1 '.SO_APO_detr(:,3),GLOBALS.XI,GLOBALS.YI, 'cubic');']);
end
clear ii var1;
Here, I'm trying to run multiple instances of the griddata function with a cubic interpolation, but because 'cubic' needs to be in quotes, it messes up the formatting of the eval function which used quotes to distinguish variables from the strings it's concatenating.
Is there such a thing as a character that suppresses the meaning of formatting symbols in this sort of case? Something like a & or $ or #? Or is there another way to do this? Or do I just have to work around the issue? For quick iterations this isn't a problem, but for larger datasets this becomes tedious writing every instance out individually.
Thanks!
Jonathan

採用された回答

Walter Roberson
Walter Roberson 2011 年 10 月 9 日
Please don't do that! Please see this FAQ
But to answer your question: to get a ' in a string, code two of them in a row, such as
',''cubic'');'
  1 件のコメント
Jonathan
Jonathan 2011 年 10 月 9 日
Thanks, Walter.
The '' trick is exactly what I needed for the present time, but I will eventually switch over to a system of pre-allocating and not using eval functions as much. I have some bad habits accumulated from years of putting off learning logical indexing... I'm in the process of changing a lot of my code to improve this.
If I can't sort out how to change over the the system described in the FAQ, I'll ask a follow-up.
Thanks,
Jonathan

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeVariables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by