Find a variable and change its value depending on the size

2 次查看(过去 30 天)
Hello all.
I will present my case. I have a workspace with many variables. What I want to do is to find in the workspace all the variables that have more than one row and transpose them. I do not want to change their names, only their value. I am trying to use "who" command, but I am having difficulties changing the value of the variables.
Regards.

回答(1 个)

Paul Shoemaker
Paul Shoemaker 2018-3-1
You can try using the "whos" command instead, like so:
vars = whos; % Get all variables in the workspace, along with size, class, bytes, etc
vars = vars(ismember({vars.class},'double')); % Get only the variables that are "double" (you might not want this)
size = [vars.size]; % Get size of variables, with odd indexes being height and even being width
height = size(1:2:end); % Get height of variables
transposeIdx = height>1; % Get index of variables that need to be transposed
transposeVarNames = {vars(transposeIdx).name}; % Names of variables to transpose
Now loop through each qualified variable in the workspace and transpose it
for idx = 1:numel(transposeVarNames)
currentVarName = transposeVarNames{idx};
eval(['currentVarName = currentVarName'';']);
end
Paul Shoemaker

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by