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.
0 件のコメント
回答 (1 件)
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!