Display Parameter with Properties in Command Window

6 ビュー (過去 30 日間)
Nick
Nick 2016 年 12 月 1 日
コメント済み: Nick 2016 年 12 月 6 日
Hello,
I would like to loop through the variables in my Workspace and display the properties of certain variables in the Command Window. Using "whos", I can loop through all the variables and filter them as I desire:
tempvar_s = whos;
for tempvar_i = 1:length(tempvar_s)
% Include any filters here in the IF statement clauses
if (strcmp(tempvar_s(tempvar_i).name, 'tempvar_s')) || (strcmp(tempvar_s(tempvar_i).name, 'tempvar_i')) || (strcmp(tempvar_s(tempvar_i).name, 'tempstrFileName'))
% do nothing
else
disp(tempvar_s(tempvar_i).name)
disp(tempvar_s(tempvar_i))
end
end
My problem is that when I use the "disp" command to display the variable using my script, I get the structure from whos, like in the following example:
p1_kPa
name: 'p1_kPa'
size: [1 1]
bytes: 112
class: 'Simulink.Parameter'
global: 0
sparse: 0
complex: 0
nesting: [1x1 struct]
persistent: 0
But if I type the same example variable into the Command Window and hit enter, I get a different list:
p1_kPa =
Parameter with properties:
Value: 101.3250
CoderInfo: [1x1 Simulink.CoderInfo]
Description: 'Ambient pressure in kPa'
DataType: 'single'
Min: 0
Max: 1000
DocUnits: 'kPa'
Complexity: 'real'
Dimensions: [1 1]
Can anyone advise how I can get my script to print out the second data set rather than the first?

回答 (1 件)

Vishal Neelagiri
Vishal Neelagiri 2016 年 12 月 6 日
This is an expected behavior because when you use 'tempvar_s = whos' command in your script, you are saving specific information about the workspace variables into a structure array named 'tempvar_s'. This struct has the fields like name, size, bytes etc.
In order to display the dataset similar to the second one rather than the first, you can try using a script similar to this:
a = 4;
p1 = Simulink.Parameter;
save test.mat a p1
x = load('test.mat')
x.p1
  1 件のコメント
Nick
Nick 2016 年 12 月 6 日
Vishal, thank you for the reply. Unfortunately this still doesn't help me as I can't loop through all the variables with this approach, correct? I have to manually type each variable name.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT-Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by