Reputation: 1181
I am trying to extract data from a uitable
I have created and export it into an Excel sheet with the Column Headers along with it. By it keeps throwing an error, stating:
Stacktrace:
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
Error in FatherSonGUI>generateWAR (line 124)
num = [col';data]
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in FatherSonGUI (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)FatherSonGUI('generateWAR',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Example Picture:
Here's a sample of my Code that I have written:
dat = dyn_conformer.Data;
set(f,'name','Title','numbertitle','off') %renames the Title Figure
cnames = {'Task Mnemonic','Success Status','External Update Required', 'Correlation ID', 'Event Name','External System','Tech Exception Status','Returned Status','Return Cancel','Return Customer','Return Technical'};
rnames = {'1','2','3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20','21', '22', '23', '24', '25'};
t = uitable('Parent',f,'Data',dat,'ColumnName',cnames,...
'RowName',rnames,'Position',[10 100 1150 370]); % size of the values inside the figure object
col = get(t,'ColumnName')
data = get(t,'Data')
num = [col';data]
xlswrite('show.xls',num)
The data is being compiled from a database, with simple data within the fields. If I were to remove the col'
element from the num
variable, it exports only the data. However, I would like to export the column names and the data together, where in the end it will look like a proper spreadsheet.
I would appreciate some help on this.
Upvotes: 0
Views: 486
Reputation: 12214
Just like the error is telling you, the dimensions of your 'col' and 'data' arrays are not consistent. Based on the sample image, the number of columns in your data is greater than the length of your header array. You either need to define all of your headers or trim your data array to the number of defined columns.
The latter:
num = [col';data(:,1:length(col))];
Though this will trim them in a non-specific manner.
Upvotes: 1