Borrar filtros
Borrar filtros

Find a variable and change its value depending on the size

2 visualizaciones (últimos 30 días)
igdbak
igdbak el 19 de En. de 2018
Respondida: Paul Shoemaker el 1 de Mzo. de 2018
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.

Respuestas (1)

Paul Shoemaker
Paul Shoemaker el 1 de Mzo. de 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

Categorías

Más información sobre Tables en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by