Display Parameter with Properties in Command Window
6 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Vishal Neelagiri
on 6 Dec 2016
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
See Also
Categories
Find more on Workspace Variables and MAT-Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!