Hi @Jack Lebar ,
To successfully display both cell array data and numeric matrix data in a UITable in MATLAB's AppDesigner, it is essential to ensure that the data types are compatible for concatenation. In MATLAB, cell arrays and numeric arrays cannot be directly concatenated using standard horizontal concatenation. Instead, we need to convert the numeric data into a cell array format before concatenation. You have an 8x1 cell array S containing labels and several numeric matrices (e.g., D, Long, Lat, Elev, X2, Y2), all of which have 8 rows. To concatenate the cell array with the numeric matrices, convert the numeric matrices into cell arrays. This can be done using the num2cell function. Once all data is in cell array format, you can concatenate them horizontally. Finally, assign the concatenated data to the Data property of the UITable. Here is the complete code that you can use in your AppDesigner app:
% Assuming you have the following data: S = {'S1'; 'S2'; 'S3'; 'S4'; 'S5'; 'S6'; 'S7'; 'S8'}; % 8x1 cell array D = rand(8, 1); % Example numeric matrix (8x1) Long = rand(8, 1); % Example numeric matrix (8x1) Lat = rand(8, 1); % Example numeric matrix (8x1) Elev = rand(8, 1); % Example numeric matrix (8x1) X2 = rand(8, 1); % Example numeric matrix (8x1) Y2 = rand(8, 1); % Example numeric matrix (8x1)
% Convert numeric matrices to cell arrays D_cell = num2cell(D); Long_cell = num2cell(Long); Lat_cell = num2cell(Lat); Elev_cell = num2cell(Elev); X2_cell = num2cell(X2); Y2_cell = num2cell(Y2);
% Concatenate all data into a single cell array combinedData = [S, D_cell, Long_cell, Lat_cell, Elev_cell, X2_cell, Y2_cell];
% Assign the combined data to the UITable app.UITable.Data = combinedData;
% Optionally, set the column names for better clarity app.UITable.ColumnName = {'Labels', 'D', 'Long', 'Lat', 'Elev', 'X2', 'Y2'};
Please see attached.
In the above code snippet, cell array S and numeric matrices are defined. The numeric matrices are generated using rand for demonstration purposes. Each numeric matrix is converted to a cell array using num2cell, which allows for proper concatenation with the cell array S. The cell array S and the converted numeric cell arrays are concatenated horizontally into combinedData. The concatenated data is assigned to the Data property of the UITable. Additionally, column names are set for clarity.
By following the steps outlined above and utilizing the provided code, you should be able to successfully display both cell array and numeric data in your UITable without encountering any concatenation errors.
Hope this helps.
Please let me know if you have any further questions.