matlab - Remove first 2 letters from workspace variables -
let's have .mat file , know each of variables in has xy in front of (e.g. xyjanuary, xyfebruary, xymarch , on...) , want remove xy.
i have looked @ this , tried copy adds xy variable (xyxyjanuary, xyxyfebruay,...) want (january, februay,...).
x= load('file.mat'); % load structure x names=fieldnames(x); % names of variables iname=1:length(names) % start loop x.(['xy', names{iname}]) = x.(names{iname}); % problem x = rmfield(x, names{iname}); end save ('newfile.mat', '-struct', 'x'); %save
x= load('file.mat'); % load structure x names=fieldnames(x); % names of variables iname=1:length(names) % start loop x.([names{iname}(3:end)]) = x.(names{iname}); % no more problem x = rmfield(x, names{iname}); end save ('newfile.mat', '-struct', 'x'); % save you added 'xy' lhs of line, makes add final solution. did chop off first 2 entries, keep rest, hence (3:end). works on test case created.
Comments
Post a Comment