Find a variable and change its value depending on the size
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponses (1)
Paul Shoemaker
le 1 Mar 2018
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
0 commentaires
Voir également
Catégories
En savoir plus sur Whos 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!