matlab - Vector length comparison whose names are stored in a cell -
there vectors in workspace different vector lengths. have string cell contains vector names. want use cellfun spit out length of these vectors.
for example,
t1 = 1x10 double t2 = 1x100 double t3 = 1x20 double cel = {'t1','t2','t3'}; cellfun(@(c) eval(['length(',c{:},')']),cel)
i thought doing following job, doesn't. have reasons why need use cellfun , eval problem.
can point out what's wrong? error messages are:
cellfun(@(c) eval(['length(',c{:},')']),cel) cell contents reference non-cell array object. cellfun(@(c) eval(['length(',c(:),')']),cel) error using horzcat dimensions of matrices being concatenated not consistent. cellfun(@(c) eval(['length(',[c{:}],')']),yvar) cell contents reference non-cell array object.
depending on variation tried.
or better yet. end goal check if length vectors same. if there way without looping, that'd great.
you can use whos
l={} ct = 1:length(cell) w=whos(cel{ct}); l{ct} = w.size; end
and agree comment. rewrite code don't need weird workarounds.
Comments
Post a Comment