- "readcell": https://www.mathworks.com/help/releases/R2021a/matlab/ref/readcell.html
- "reshape": https://www.mathworks.com/help/releases/R2021a/matlab/ref/reshape.html
- "cell2table": https://www.mathworks.com/help/releases/R2021a/matlab/ref/cell2table.html
Array with name, number, date in the same column and I need help to split them
14 views (last 30 days)
Show older comments
Hello community,
I am new to matlab and I imported an excel file which includes data of string, number and dates (all data are in the same column) and I want to split it into 3 columns.
Information of the data:
string=name
number=ID
date=birthdate
example:
Person XYZ
12345678
01.01.1990
Person ABC
19876543
01.11.1995
and I want to "transpose" the data like that:
column 1 column 2 column 3
Person XY 12345678 01.01.1990
Person ABC 19876543 01.11.1995
I think its not that difficult to solve this problem, I already tried so solve it with a for loop and if statement but I have some problems to get the right syntax.
Thanks in advance!
stay safe!!! :-)
0 Comments
Answers (1)
Arjun
on 10 Jun 2025 at 6:14
I understand that you have an Excel file where all the data is stored in a single column, and the entries follow a repeating pattern: a name, followed by an ID number, and then a date. You want to restructure this data into a table format where each row represents one complete record, with separate columns for the name, ID, and birthdate.
You can use MATLAB’s "readcell" function to import the data from the Excel file into a cell array. Since the data is organized in a repeating pattern (e.g., name, ID, date), you can calculate the number of rows required by dividing the total number of elements in the cell array by 3. Then, use the "reshape" function to reorganize the data into a matrix with three columns—one for each data type. Finally, for better readability and further processing, you can convert the reshaped cell array into a table using the "cell2table" function.
Kindly refer to the code section below for the implementation of the above process:
% Read the data from Excel, specify your file name
rawData = readcell('dummy_data.xlsx');
% Determine number of rows
numRows = length(rawData) / 3;
% Reshape the data and then transpose
reshapedData = reshape(rawData, 3, numRows)';
% Convert to table for better readability
T = cell2table(reshapedData, 'VariableNames', {'Name', 'ID', 'date'});
% Display the result
disp(T);
You can refer to the official documentation for each of the MATLAB functions mentioned using the links provided below:
I hope this helps!
0 Comments
See Also
Categories
Find more on Data Import from MATLAB 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!