Using cellfun with function that can return nothing
显示 更早的评论
I am trying to use the cellfun function to execute the evalin function on a cell array of char vectors, which correspond to elements in the base workspace. Sometimes the char vectors are empty, in order to ensure the order of the elements matches with other cell arrays of data.
a = Simulink.Signal;
b = Simulink.Signal;
C = {'a', '', 'b'};
X_values = cellfun(@(x) evalin('base', x), C, 'UniformOutput', false);
Executing the last line gives the error:
Error using @(x) evalin('base', x)
Error: This statement is incomplete.
Is seems that the issue is that evalin returns nothing when it does not find the '' in the base workspace. Is there some way to make the cellfun work in this case, or do I need to use a loop?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!