0

I have the following situation:

PA_2 = inv(T2)*[PA_0;1]

Where PA_0 is a 2x1 vector and PA_2 is a 3x3 matrix. The answer will be:

[2,14903810567666;-0,722243186433546;1]

The problem is that i want to leave out the 1. So i want to get a 2x1 vector in stead of a 3x1 vector.

What would i have to change/edit to this line: PA_2 = inv(T2)*[PA_0;1] ?

Do any of you guys know the answer to my problem?

Thanks for your time,

Justin

  • So @Just van Til does any of the answers below helped you? If so please upvote/mark it as accepted. Thanks! – Benoit_11 Mar 09 '15 at 13:17

2 Answers2

1

I don't believe you can do it in one line (someone else may chime in on that) so what i would do is this

PA_2 = inv(T2)*[PA_0;1];
PA_2 = PA_2(1:2);

the : means range. the left is your start index and the right is your end index. You can even use this notation with matricies. Just for example

a = [1,2,3;4,5,6;7,8,9];
a(2:3,1:2)
%produces 
%ans =
%     4     5
%     7     8

and one more helpful tidbit, if you were using longer vectosrs/matricies you can use the end keyword. It automatically find the last index. So for your example you could do

PA_2 = inv(T2)*[PA_0;1];
PA_2 = PA_2(1:end-1);     %leaves out the last element

hope that helps

andrew
  • 2,451
  • 1
  • 15
  • 22
0

You might want to look at this question which has a lot of interesting answers.

For your application the undocumented function builtin works fine:

PA_2 = builtin('_paren', inv(T2)*[PA_0;1], 1:size(T2,1)-1)

Note that you can't use the keyword end with it, so you have to use the size of T2 for instance to input the right number of elements.

Community
  • 1
  • 1
Benoit_11
  • 13,905
  • 2
  • 24
  • 35