MATLAB: Error using horzcat- dimensions of matrices being concatenated are not consistent

arrayhorzcatMATLAB

Code:
[file_name, ~] = uigetfile('.txt','Open Calibration File');
A = readtable(file_name);
slopes = table2array(A(:,1));
intercepts = table2array(A(:,2));
unitss = table2array(A(:,3));
*t.Data = [slopes,intercepts,unitss];* _this is the error line_
slopes and intercepts are both 4×1 double, and unitss is 4×1 cell with text inside. I've already tried cellstr on unitss, and I've double checked the sizes. My code works when I remove unitss, so I know that is part of the problem! Can anyone tell me how to fix it?

Best Answer

A is a table. t is a structure. You're trying to create an array by stitching together two double vectors and a cell array. You can't do that. If you want you could put each double into a cell , and then the whole thing is a cell array. But why would you do that when you'd essentially just be building up your original A in a cell array instead of a table? It doesn't make sense. If you want the data field of your "t" structure to be the table, simply do
t.data = A;