lonstud
lonstud

Reputation: 525

print a matlab structure in table format

I am trying to visualize data stored in my data structure so that I can spot patterns in them.

The data which I am trying to visualize is stored in following structure format: master_data.(A).(B).{values} Here, A are various insturments which define the data. Lets call these instruments A1, A2, A3 and so on. B are various properties of these instruments. Lets call them B1, B2, B3 and so on. Each insturment of A has these same properties B1, B2, B3 and so on. Now, values are cell arrays having 5 different double values. So, we might have masterdata.(A1).(B1) having values 1,2,3,4,5 and masterdata.(A1).(B2) having values 5,4,3,2,1.

now I want to print these values in the following way to easily visualize them

          B1       B2      B3 .....

A1        1         5
          2         4
          3         3
          4         2
          5         1
A2

.
.
.

I understand there might be better way to store data than structure but I am most comfortable working with structures and so I have generated my data in this format. Also, I can write a loop to iterate through all elements of structure and print out values but I am not sure how to take care of formatting issues.

I request you to let me know how to print these values in the required format(we may convert data to a more suitable data type if it gets the job done). I am not giving sample code for iterating to print existing structure as I suspect there is a better way to convert my structure to something like table or map and simply printing that structure.

Upvotes: 0

Views: 145

Answers (1)

Marouen
Marouen

Reputation: 945

Let's call your master_data MD. Here is how you can do it:

fields=fieldnames(MD);
res=[];
for i = 1:numel(fields)
  res=[res;struct2dataset(MD.(fields{i}))];
end

Upvotes: 1

Related Questions