Error using table (line 253)

1 view (last 30 days)
% Full vehicle parameters
R_AV = 0.3; % wheel radius (m),
M_AV = 1626; % Mass(kg)
L_AV = 3.0; % length(m)
Je_AV = 4.5; % M.O.I engine(kg m2)
Cd_AV = 0.29; % Drag efficient
Crr_AV = 0.01; % Rolling Resistance
AF_AV = 1.8; % Frontal areaof vehicle (m)
W_AV = 1.6; % Width of the vehicle (m)
% Analysis of 1:8 ratio scale factor of dimensionless Radius
% 1/8 = r/R;
r_sv = R_AV*1/8;
r25_sv = R_AV*1/25;
% Analysis of sv LENGTH
% 1/8 = l/L;
l_sv = L_AV*1/8;
l25_sv = L_AV*1/25;
pi_AV = R_AV/L_AV;
pi_SV = r_sv/l_sv;
pi_SV25 = r_sv/l_sv;
Radius = [R_AV; r_sv; r25_sv];
length = [L_AV; l_sv; l25_sv];
Mode = {'Actual Vehicle' 'scaled vehicle 1:8''scaled vehicle 1:25'};
Pi = [pi_AV;pi_SV;pi_SV25];
T = table(Mode,Radius,length,Pi)
i want to display the table with the content above. but i face a problem like,
Error using table (line 253) All variables must have the same number of rows.
Error in SV (line 37) T = table(Radius,length,Pi...

Accepted Answer

Guillaume
Guillaume on 15 Nov 2016
I assume that Mode is supposed to be the name of the columns, in which case the proper syntax should be:
T = table(Radius, length, Pi, 'VariableNames', Mode)
Unfortunately, it's still not going to work for two reasons:
  • You missed a space in your Mode declaration and as a result it only has two elements, the 2nd one being the string scaled vehicle 1:8'scaled vehicle 1:25. To fix this:
Mode = {'Actual Vehicle' 'scaled vehicle 1:8' 'scaled vehicle 1:25'};
  • column names must be valid matlab variable names, which means no space or :. If you're happy with matlab replacing invalid characters, then:
T = table(Radius, length, Pi, 'VariableNames', matlab.lang.makeValidName(Mode))
You could set the table VariableDescriptions properties to the untouched Mode if you want:
T.properties.VariableDescriptions = Mode;
but it's not that useful, as matlab only displays that description with summary:
summary(T)

More Answers (1)

Alexandra Harkai
Alexandra Harkai on 15 Nov 2016
Did you check how Mode looks like? It is a row array with 2 elements, which is not compatible with the 3-element column vectors in the table.
Mode = {'Actual Vehicle' 'scaled vehicle 1:8' 'scaled vehicle 1:25'}'
Notice the space between the last two elements, this will ensure . Mode is also transposed to be a column just like Radius, length, Pi.
  1 Comment
Guillaume
Guillaume on 15 Nov 2016
Or yes, maybe Mode is meant to be a column of a 3x4 table, in which case as Alexandra says transpose the (corrected) variable.
In that case it would be a good idea to give explicit names to the columns instead of the default Var1, Var2, ..., using the 'VariableNames' syntax I've shown.

Sign in to comment.

Categories

Find more on Introduction to Installation and Licensing 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!