Convert Cell String 'plus(0,0') to Num not using Eval or Str2Num
显示 更早的评论
Hi Friends,
Well I have a problem that's very similar to some ohter guys using str2num() or eval() functions.
The great point is: Imagine that I have this:
for i=1:1000
C{i}='plus(0,0)';
end
And I want to retrieve the number that is generated by this function (in fact I have problem greater than this, but solving this problem can help to solve the bigger picture).
A way to solve this is:
a=ones(1000,1)
for j=1:1000
a(i,1)=eval(C{i});
end
or
a=ones(1000,1)
for j=1:1000
a(i,1)=str2num(C{i});
end
or
a=cellfun(@eval,C);
The great problem using these methods is that takes a lots of time to do this.
Someone can help me to solve this problem faster!
Thanks, Adriano
2 个评论
Image Analyst
2013-5-21
How does this problem arise? In other words, why does the operation you want to perform (plus or whatever) come in as a string? It doesn't seem like the most ideal way to construct a program. Does it ever change from plus to some other operation, and if so, why? What is the "use case"?
Cristian munoz
2013-5-22
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!