Structuring and importing heterogeneous data in MATLAB?

3 views (last 30 days)
Hi,
I wish to import data from three spreadsheets regarding patient data into the most suitible MATLAB structure for further modelling and examination. The spreadsheets are structured like this:
  • BASELINE spredsheet: Contains one row per patient, the columns contain baseline data for each patient and includes a personal identifier for that individual
  • SURGICAL spreadsheet: Contains multiple rows per patient (could be 5 entires for one individual and 2 for another depending on surgeries completed), each row contains a personal identifier which indicates on which patient the row relates to
  • EVALUATION spreadsheet: Contains multiple rows per patient (could be 5 entires for one individual and 2 for another depending on evaluations completed) ,each row contains a personal identifier which indicates on which patient the row relates to
I have looked at the documentation and examples for structure arrays, tables and datasets array and understand the different uses for them. From my understanding, structure arrays seems like the best way to structure this data? Also, I don't understand how MATLAB can help with matching the relevant rows in SURGICAL and EVALUATION with the relevant person in BASELINE through traversion or similarly. In simplistic terms, is it possible to have something similar to
JohnDoe.surgeries.1 = returns all columns for John Doe's first surgery
JohnDoe.surgeries.2 = returns all columns for John Doe's second surgery
And analogous for evaluation?
Best,
Joel
  1 Comment
Ive J
Ive J on 2 Feb 2021
I would merge (see join) all different datasets into a single table, and then use groupsummary or groupfilter as appropriate. Say you've already created such a table, so you can easily access to all data for that patient:
myBiobank(myBiobank.name == "JohnDoe" & myBiobank.surgeryID == 1, :) % show me all data for this person

Sign in to comment.

Answers (1)

Sanjana
Sanjana on 24 Sep 2024
Hi,
To handle your data in MATLAB, you can indeep use structure arrays, which provide a flexible way to organize and access your data.
Kindly, refer to the following steps to achieve the same:
Step 1: Import data
baselineData = readtable('BASELINE.xlsx');
surgicalData = readtable('SURGICAL.xlsx');
evaluationData = readtable('EVALUATION.xlsx');
Step 2: Initialize Structure Array
patients = struct()
Step 3: Populate Structure Array
Loop through each patient in the baseline data and populate the structure array with their data, including surgeries and evaluations.
% Assuming 'ID' is the column name for personal identifier
for i = 1:height(baselineData)
patientID = baselineData.ID{i};
% Initialize the patient structure
patients.(patientID).baseline = baselineData(i, :);
% Find and add surgical data
surgeries = surgicalData(strcmp(surgicalData.ID, patientID), :);
patients.(patientID).surgeries = table2struct(surgeries);
% Find and add evaluation data
evaluations = evaluationData(strcmp(evaluationData.ID, patientID), :);
patients.(patientID).evaluations = table2struct(evaluations);
end
Step 4: Accessing Data
% Access baseline data for John Doe
johnDoeBaseline = patients.JohnDoe.baseline;
% Access first surgery data for John Doe
johnDoeFirstSurgery = patients.JohnDoe.surgeries(1);
% Access second evaluation data for John Doe
johnDoeSecondEvaluation = patients.JohnDoe.evaluations(2);
Hope this helps!
Regards,
Sanjana

Categories

Find more on Data Import and Analysis 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!