I am trying to create a table but somehow can't.
Afficher commentaires plus anciens
>> u = 100;
a = -9.81;
angle = 10;
angle = angle*pi/180;
ux = u*cos(angle);
uy = u*sin(angle);
tmax = -2*uy/a;
t = linspace(0,tmax,200);
vx = ux;
sx = ux*t;
sy = uy * t + 0.5*a*t.^2;
LastName = {'1:200'};
Time = [t];
Sx = [sx];
Sy = [sy];
T = table (Time,Sx,Sy,...'RowNames',LastName);
Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.
Réponses (3)
Azzi Abdelmalek
le 23 Déc 2014
Modifié(e) : Azzi Abdelmalek
le 23 Déc 2014
What those 3 dots are doing?
T = table (Time,Sx,Sy,'RowNames',LastName);
1 commentaire
Adam
le 23 Déc 2014
Star Strider
le 23 Déc 2014
Modifié(e) : Star Strider
le 23 Déc 2014
There are a few problems. One is that ‘Time’, ‘Sx’, and ‘Sy’ need to be column vectors, and ‘LastName’ needs to be a cell array.
Change to these lines and it works (or at least creates your table correctly):
LastName = strsplit(sprintf('%3d\n',1:200));
LastName = LastName(2:201);
Time = t';
Sx = sx';
Sy = sy';
T = table (Time,Sx,Sy,...
'RowNames',LastName);
EDIT — I’m using R2014b. There may be version differences.
2 commentaires
Adam
le 23 Déc 2014
Star Strider
le 23 Déc 2014
Modifié(e) : Star Strider
le 23 Déc 2014
What ‘didn’t work’ about it? When I ran it, it produced:
T =
Time Sx Sy
_______ ______ _______
1 0 0 0
2 0.01779 1.752 0.30737
3 0.03558 3.504 0.61163
4 0.05337 5.2559 0.91279
5 0.07116 7.0079 1.2108
... etc. ... to row 200
I’m a bit mystified. In your Comment to Sean’s answer you mention R2013a that does not support table, and here you mention R2014a that should support it. If you have a license for R2013a, you should be able to download and install R2013b on that same license, at least as I understand it. Then you will have table.
In the absence of being able to use table, I would use a matrix or a cell array, whatever is most convenient for you and best meets your needs.
Sean de Wolski
le 23 Déc 2014
0 votes
Table was added in R2013b. If you're using an older release, tables won't work. If your company/university is current on maintenance, you can likely upgrade at no additional cost.
1 commentaire
Adam
le 23 Déc 2014
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!