How to Convert concatenated data within a cell within a structure to an array?

4 views (last 30 days)
I am surrently developing a GUI that autmates some of the more frustrating data processing I do. I have it working, but I still need to break down my data into separate files and I am trying to further automatate it. I had to do this since some of the information I need wasn't easliy available until i found it tagged in another structure, but I am having trouble pulling that data and then eventually creating an array form it.
I have a internal program that outputs data into its own mat files and I am trying to break down that data into easier peices for data processing.
For example I want to pull velocity from this variable that is created and looks like this. The tags and name lengths do change often.
sensors.single{1, 5}.location_info = 'EventName:HEK144501o_ES:EventID:PYYI1040:Velocity:67 KPH:Location:PL:RTTF:NF'
I've tried some varaitations of code searching with strcmp or find or even cellfun and the below function I found and use other places in this code but nothing I try can pull this data. Honestly I used to work a lot with matlab but other than simple modifications, I haven't had to build anything from scratch in a long time and I feel like I stuck trying to manipulate data using commands not valid for the format. Any help would be appreciated.
cellfind = @(string)(@(cell_contents)(strcmp(string,cell_contents)));

Accepted Answer

Umar
Umar on 14 May 2024
To address the issue of extracting specific data from a variable with a dynamic structure in MATLAB, we can employ a combination of string manipulation techniques and custom functions. Let's break down the process step by step to automate the extraction of velocity information from the given variable structure.
Step 1: Define the Custom Function
The cellfind function provided by the user can be modified to search for the desired information within the complex variable. We can enhance this function to handle the unique structure of the data. Here is an improved version of the cellfind function:
cellfind = @(string) @(cell_contents) contains(cell_contents, string); Step 2: Extract Velocity Information
Given the variable structure provided by the user:
sensors.single{1, 5}.location_info = 'EventName:HEK144501o_ES:EventID:PYYI1040:Velocity:67 KPH:Location:PL:RTTF:NF'; We can extract the velocity information using the modified cellfind function as follows:
% Define the target string to search for (e.g., 'Velocity:') targetString = 'Velocity:';
% Extract velocity information velocityIndex = find(cellfun(cellfind(targetString), {sensors.single{1, 5}.location_info}));
if ~isempty(velocityIndex) velocityInfo = sensors.single{1, 5}.location_info{velocityIndex}; % Further processing of velocityInfo as needed disp(velocityInfo); % Display the extracted velocity information else disp('Velocity information not found.'); end By utilizing the contains function within the custom cellfind function, we can efficiently search for the 'Velocity:' tag within the location_info variable and extract the corresponding velocity information.

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!