Borrar filtros
Borrar filtros

Display Parameter with Properties in Command Window

9 visualizaciones (últimos 30 días)
Nick
Nick el 1 de Dic. de 2016
Comentada: Nick el 6 de Dic. de 2016
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?

Respuestas (1)

Vishal Neelagiri
Vishal Neelagiri el 6 de Dic. de 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
  1 comentario
Nick
Nick el 6 de Dic. de 2016
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements 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