Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 29 Mär. 2013
Bearbeitet: Sean de Wolski am 29 Mär. 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}));

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by