converting string to num and table
显示 更早的评论
I have a table containing string data that represents cyclone certain and uncertain tracks. Each cell in the table may contain multiple track numbers (seperated by a space), where the presence of 'x' beside a number indicates uncertainty in that track. For example, in tempData(7,1) = "30 25x", '30' is a certain track, and '25' is uncertain.
I need to write a code that parses each cell in a column of tempData, separates the track numbers and their uncertainty markers ('x'), and outputs a (in this case) 4-column table for each column in tempData. The headers of the output table should be track1, uncert1, track2, uncert2, corresponding to the parsed tracks and their certainty indicators (marked by 0 or 1). If the input has 3 tracks, the then output table should have a 6 column table
Finally, I want to store each output table in a cell array marked by the varname of the input column (y98, y99, y20, etc), as I need to process over 200 columns in my original data.
I have attached a sample input (tempData) and output for the first coumn that i want (tempDataOut).
Thanks in advance.
采纳的回答
更多回答(1 个)
Karanjot
2024-8-22
Hi Sarvesh,
To achieve this task, you can write a script in MATLAB that processes each column of your tempData table, parses the track numbers and their uncertainty markers, and stores the results in a cell array. Here's a step-by-step guide to help you accomplish this:
- Initialize Variables: Create a cell array to store the output tables, and define the headers for the output tables.
- Parse Each Column: Loop through each column in tempData, and for each cell, split the string by spaces to separate track numbers and uncertainty markers.
- To carry out the string manipulation as described above, You can use the strsplit function to split a string into parts based on a delimiter and the endsWith function to check if a string ends with a specified substring. For example:
parts = strsplit('30 25x', ' '); % Splits into {'30', '25x'}
isUncertain = endsWith('25x', 'x'); % Returns true
- Create Output Table: For each parsed cell, determine the number of tracks and uncertainty indicators, and create a table with appropriate headers.
- Store Results: Store each output table in the cell array with the corresponding variable name.
To know more about the functions mentioned above, Please refer to the following documentation:
I hope this helps!
类别
在 帮助中心 和 File Exchange 中查找有关 String 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!