Merge a large number of tables with different lengths aligned by specific column variable
3 次查看(过去 30 天)
显示 更早的评论
I have a spreadsheet that was imported using the following code:
filename = 'Baseline ROI analysis SOMA.xlsx'; %identify name of the file
sheets = sheetnames(filename); %load string of sheet names
disp(sheets)
raw_data = [] %initialize
%loop through and load each sheet into a raw_data (cell format)
for k = 1:length(sheets)
raw_data{k} = readtable(filename,'Sheet',sheets(k));
end
The 1x20 cell contains 20 tables with 6 column variables per table.
I manually extracted each table to a variable, removing 3 variables that I do not need. (I assume there's a faster way to do this, but I can only think of dynamic variable names which I believe are frowned upon).
Example:
data1 = removevars(raw_data{1,1},{'Name','ND_M','ND_Z'})
data2 = removevars(raw_data{1,2},{'Name','ND_M','ND_Z'})
data3 = removevars(raw_data{1,3},{'Name','ND_M','ND_Z'})
The remaining variables - time(Time_s_), video frame #(ND_T), and average intensity(x_1_470Nm_) are output into the individual tables.
I've tried using outerjoins, but since I can't set an index (like a pandas dataframe), I can't merge on the frame values.
testmerge = outerjoin(data1,data2)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/279497/image.png)
Is there a way to merge the tables so that all values are retained, and they can be aligned by frame #?
Also, would there be a way to do so without chaining outerjoin(data1,outerjoin(data2,outerjoin(data3,outerjoin(data4,data5))))... ?
Thanks in advance!
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!