Error using vertcat, dimensions of arrays being concatenated are not consistent

51 views (last 30 days)
Results = [beamontime; beamofftime; dwelltime; avgxbeam; avgybeam; avgbeam; avgxcentroid; avgycentroid; jitter; avgpower; avgpeakirr; framerate; dwellframerate];
Name = [ 'Beam On (UTC)'; 'Beam Off (UTC)'; 'Dwell Time (s)'; 'Average X-Diameter (cm)'; 'Average Y-Diameter (cm)'; 'Average Diameter (cm)'; 'Average X-Centroid (cm)'; 'Average Y-Centroid (cm)'; 'Jitter (cm)'; 'Average Power (kW)'; 'Average Peak Irradiance (W/cm^2)'; 'Frame Rate (Hz)'; 'Dwell Time Frame Rate (Hz)'];
T = table(Name, Results)
I have two arrays with 1 column and 13 rows. I am trying to make a 2 column table with the names on the left and results on the right. The first 3 results are durations and the rest are double values. Please help, I feel like making tables is so hard on Matlab!
  1 Comment
Stephen23
Stephen23 on 16 Nov 2022
"The first 3 results are durations and the rest are double values."
You will have to store these in a container array, e.g. a cell array, because table columns/variables must be one homogenous data type. Mixing data types like this is probably not the best use of a table.
"Please help, I feel like making tables is so hard on Matlab!"
The error message you get is due to concatenating together incompatible char vectors. It is unrelated to tables.

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 16 Nov 2022
Edited: Stephen23 on 16 Nov 2022
Use a string array rather that trying to vertically concatenate incompatible character vectors:
Name = ["Beam On (UTC)"; "Beam Off (UTC)";..];
% ^ ^ ^ ^ string scalars, not character vectors.
  2 Comments
Stephen23
Stephen23 on 16 Nov 2022
Tested:
Name = ["Beam On (UTC)"; "Beam Off (UTC)"; "Dwell Time (s)"];
Results = [1;4;pi];
T = table(Name,Results)
T = 3×2 table
Name Results ________________ _______ "Beam On (UTC)" 1 "Beam Off (UTC)" 4 "Dwell Time (s)" 3.1416

Sign in to comment.

More Answers (0)

Categories

Find more on Matrices and Arrays 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!