Filter löschen
Filter löschen

setting up a nested data structure

109 Ansichten (letzte 30 Tage)
scobug411
scobug411 am 20 Okt. 2020
Kommentiert: scobug411 am 21 Okt. 2020
I have a large data set containing a 300x1 matrix of various male heights and another 300x1 matrix of female heights. I sorted these heights manually using a selection sort algorithm and also using matlab's sort() command. I then timed the manual and matlab excecutions using the tic/toc commands. Basically I need to create a nested strucure that includes the sorted male and female heights as well as the manual and matlab run times for each gender. the included image details what needs to be stored into what
How do I put the manual and matlab data into the appropriate gender (female or male)? here is the code I used (its very wrong)
(female=300x1 height matrix
male=height matrix)
SortedHeights=struct('Female Heights',female,struct('Manual',manual_time,'Matlab',matlab_female),'Male Heights',male,struct('Manual',manual_time,'Matlab',matlab_male))
i apologize if any of my wording is confusing lol

Akzeptierte Antwort

Jeff Miller
Jeff Miller am 20 Okt. 2020
Your information architecture diagram doesn't look quite right. For example, your [Females] should be a structure that holds heights and times, but you have it as an array of heights. I think you want something like this:
female_times = struct('Manual',manual_time,'Matlab',matlab_female);
Female = struct('Heights',female,'Times',female_times);
% ditto for males to make struct Male
SortedHeights=struct('Female',Female,'Male',Male)
FWIW, I would question using an information architecture like this in the first place. Why not, for example, just keep the times in a 2x2 array (gender, manual/matlab)?
  1 Kommentar
scobug411
scobug411 am 21 Okt. 2020
part of the assignment was to store the data in a nested structure and the diagram was the one given in the instructions, but this makes alot of sense, thank you so much!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by