Find a variable and change its value depending on the size

조회 수: 2 (최근 30일)
igdbak
igdbak 2018년 1월 19일
답변: Paul Shoemaker 2018년 3월 1일
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에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by