![]() |
Exploiting MATLAB's Data Structures |
One of the most important uses of the cell array is to hold a bunch of strings of different lengths. In this problem you will learn how to work with cell arrays of strings.
Goal: Determine the list of variables that will conflict when you load in a MAT-file. Use who and who -file to create a list of the variables in each workspace. Use setdiff or intersect to determine if there will be any name clashes.
Key concepts: working with cell arrays of strings, creating cell arrays of strings, operating on cell arrays of strings.
Key functions: who, whos, load, intersect, strmatch
who -file topo
clearload topo
work = whofile = who('-file','world')
conflicts = intersect(work,file)or
conflicts = {};for i=1:length(work)k = strmatch(work{i},file,'exact')if ~isempty(k)conflicts = [conflicts;file(k)];endendThe solution that uses strmatch would be preferred if partial matches are allowed. Just get rid of the 'exact' flag. The conflicting variable is 'topo'.
![]()
Copyright © 1997 The MathWorks, Inc.
clay@mathworks.com
$Revision$ $Date$