フィルターのクリア

Semi-repeatable Cellfun Error

1 回表示 (過去 30 日間)
Tom
Tom 2012 年 8 月 2 日
I'm quite thrown by this problem: I have a line which crops up in a few functions within a program, which uses cellfun to convert some numeric positive/ negative data into strings formatted for currency:
MoneyDisp(:,3) = cellfun(@(x) sprintf('£%0.2f',abs(x)),MoneyDisp(:,3),'UniformOutput',false);
Where MoneyDisp is a cell array, the third column of which has the numeric data in. For a while now, when I try and run it (on R2010a 64 bit, Windows 7), I get the following error:
??? Undefined function or variable 'create_sfh%1@(x)sprintf('£%0.2f',abs(x))'.
So something strange seems to be happening with the execution of the anonymous function to mash the whole thing into one string? If I use
dbstop if error
to catch the error, I can run that line in the command window and it works without any problems. If I then exit debug mode and run the function again, sometimes the error disappears and everything's fine from then on, other times Matlab crashes owing to a segmentation violation.

採用された回答

Oleg Komarov
Oleg Komarov 2012 年 8 月 2 日
You can try this solution to format currencies: http://www.mathworks.com/matlabcentral/answers/32171#answer_40659
I suggest to file in a technical support request with TMW.
  1 件のコメント
Tom
Tom 2012 年 8 月 3 日
Thanks, Oleg. For what it's worth, it seems to be working if I use a standard function instead, e.g.
cellfun(@formatfcn,...)
...
function y formatfcn(x)
y=sprintf('£%0.2f',abs(x))

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

その他の回答 (0 件)

カテゴリ

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