Effacer les filtres
Effacer les filtres

How to filter out missing variables for functions when importing .txt files

1 vue (au cours des 30 derniers jours)
I am importing a text file and evaluating the data in the file versus baseline data. The problem I am having is that the text file to be evaluated is sometimes missing variables.
How can I efficiently besides, using ~exist() for every variable, filter out the data that is not present

Réponse acceptée

Sean de Wolski
Sean de Wolski le 29 Mar 2013
Modifié(e) : Sean de Wolski le 29 Mar 2013
First, I warn you that this approach of "poofing" variables might be a bad idea that could lead to difficult to debug issues further down the line.
Second, to do this efficiently you could use the structure output from whos() and ismember() to identify missing variables:
clear;
x = 1;
y = 7;
varsWanted = {'x','y','z'};
varsPresent = whos;
missing = varsWanted(~ismember(varsWanted,{varsPresent.name}));

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by