Viewing multi level structures in the the Workspace

5 views (last 30 days)
I am working with a very complex structured data set with many levels. When I need to "drill down" and see the values four levels deep in the structure, my desktop is littered with the higher levels I had to open just to get down to the one I'm looking at. Is there a setting in MATLAB that allows the previous window to close when the next level is opened. I know this is not always desirable. But I am spending a lot of time closing the trail of breadcrumbs that I don't need.
  2 Comments
Jan
Jan on 5 Jun 2018
What exactly is a "data set with many levels"? A nested struct? Why is your desktop filled when you "see the values"? How do you display them? What is the "previous window"?
Mike Smith
Mike Smith on 5 Jun 2018
What exactly is a "data set with many levels"? A nested struct? ----> Yes, a nested structure e.g.
telemetry.gps.position.latitude
Why is your desktop filled when you "see the values"? How do you display them? What is the "previous window"?
In the Workspace, I open the nested structure "telemetry". Under "telemetry", there are several levels (battery, gps, ins, comms, etc.) I open "gps". The "telemetry" window remains open on my desk top. In "gps" the list of categories would be (position, speed, quality, etc.). I open "position". The "telemetry" and "gps" windows remain open. Under gps, the list of categories would be (latitude, longitude, altitude) I click on "latitude" and see the vector of latitude values. Open on my desk top are: telemetry,gps,position, and latitude. When I am finished examining the contents of the latitude values, I have to close all four windows.
This is a very simplified example and the actual data structure is much more complex. I also understand that this file is needlessly complex in its nesting, but I did not design it and I must deal with what I get.
Thanks for your help.

Sign in to comment.

Answers (1)

OCDER
OCDER on 5 Jun 2018
You could use this recursive function to display the variable stored in the Nth level of a structure. This is a starting template code, so you'll have to modify it to fit your needs.
%showNSD will show the nested structure data at the Nth level
%
% EXAMPLE
% clear S
% S.a.b.c1.d.e = 1;
% S.a.b.c1.d.f = 2;
% S.a.b.c1.d.g = 3;
% S.a.b.c2.d = 4;
% S.a.b.c3.d = 5;
%
% >>showNSD(S, 5)
% 1
% 2
% 3
% >>showNSD(S, 4)
% 4
% 5
function showNSD(S, MaxLevel, varargin)
if ~isempty(varargin)
CurLevel = varargin{1};
else
CurLevel = 0;
end
%fprintf('%sLEVEL_%d\n', repmat('.', 1, CurLevel), CurLevel); %Uncomment if you want to see the level #
if CurLevel == MaxLevel
disp(S)
return
elseif ~isstruct(S)
%disp(S) %Uncomment if you want to also show non-struct values for
%levels < MaxLevel
return
end
FieldName = fieldnames(S);
for j = 1:length(FieldName)
showNSD(S.(FieldName{j}), MaxLevel, CurLevel+1);
end

Categories

Find more on Structures 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!