Using cellfun with function that can return nothing
Mostra commenti meno recenti
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?
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Structures in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!