I am trying to create a table but somehow can't.

>> 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 [.

2 Kommentare

Sara
Sara am 23 Dez. 2014
At what line is the error? Works just fine for me once 'RowNames',LastName); is put on a different line
Adam
Adam am 23 Dez. 2014
how to put it on a different line?tried pressing enter, didn't help.sorry for the stupid question but i am just a begginner in matlab.

Melden Sie sich an, um zu kommentieren.

Antworten (3)

Azzi Abdelmalek
Azzi Abdelmalek am 23 Dez. 2014
Bearbeitet: Azzi Abdelmalek am 23 Dez. 2014

0 Stimmen

What those 3 dots are doing?
T = table (Time,Sx,Sy,'RowNames',LastName);

1 Kommentar

Adam
Adam am 23 Dez. 2014
i tried doing that but got this instead:
>> T = table (Time,Sx,Sy,'RowNames',LastName);
Undefined function 'table' for input arguments of type 'cell'.

Melden Sie sich an, um zu kommentieren.

Star Strider
Star Strider am 23 Dez. 2014
Bearbeitet: Star Strider am 23 Dez. 2014

0 Stimmen

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 Kommentare

Adam
Adam am 23 Dez. 2014
i'm using an older version, R2014a. Tried your coding but didn't work. is there any other way that i can show the data?
Star Strider
Star Strider am 23 Dez. 2014
Bearbeitet: Star Strider am 23 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Sean de Wolski
Sean de Wolski am 23 Dez. 2014

0 Stimmen

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.

Tags

Gefragt:

am 23 Dez. 2014

Bearbeitet:

am 23 Dez. 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by