How to pass a “.mat” file as an argument of user defined function?
    3 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    Explorer
      
 le 30 Jan 2016
  
    
    
    
    
    Réponse apportée : Walter Roberson
      
      
 le 31 Jan 2016
            Please write demo code.
0 commentaires
Réponse acceptée
  Walter Roberson
      
      
 le 31 Jan 2016
        function listvars(matfilename)
  if ~ischar(matfilename) || ~exist(matfilename,'file')
    error('argument must be the name of an existing file');
  end
    try
      datastruct = load(matfilename);
    catch
      error('Failed in loading from file, might not be real .mat file');
    end
    fn = fieldnames(datastruct);
    if isempty(fn)
      fprintf('File loaded but it had no variables stored in it\n');
    else
      nv = length(fn);
      fprintf('File "%s" contains the following %d variable(s)\n', matfilename, nv);
      for K = 1 : nv
        thisvarname = fn{K};
        thiscontent = datastruct.(thisvarname);
        fprintf('variable "%s", class "%s"\n', thisvarname, class(thiscontent));
      end
    end
0 commentaires
Plus de réponses (0)
Voir également
Catégories
				En savoir plus sur Workspace Variables and MAT Files dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

