Understanding Matrix Addition and Initialization
4 views (last 30 days)
Show older comments
I am a Matlab newbie, so please be gentle.
I am trying to port some Matlab code to C++ and am having trouble understanding some of the lines.
In particular:
a = c(:,1);
b = c(:,2);
T=[0:nn-1]';
TT=ones(nn,1);
TTT=round(T*lt+TT*temp1);
SegmentX(temp3,:)=a(TTT);
SegmentY(temp3,:)=b(TTT);
Here, nn and temp 1 are integers while lt is a float/real.
As I understand it, the first line should create a single row, multi-column matrix/vector (called T) and fill it with 0 to nn-1. Correct?
Then, the matrix is transposed to create a single column, multi-row matrix/vector. Correct?
Then, another matrix/vector (called TT) is created, that is single column, multi-row and filled with ones.
Finally, an integer (called TTT) is created by adding T*lt and TT*temp1 and rounding the result.
Something must be wrong in my understanding because a matrix/vector plus a matrix/vector should yield another matrix/vector when I know that TTT is an integer.
Where am I going wrong? Any help appreciated.
3 Comments
David Goodmanson
on 24 Feb 2017
Edited: David Goodmanson
on 24 Feb 2017
Hi James, T and TT are column vectors as you say, but (assuming nn >= 2 so that T and TT are not merely scalars), it's hard to see how TTT could be a scalar. When a column vector of dimension (nn,1) is multiplied by an object on the right, that object must be an array of size (1,m) (i.e. a row vector, or a scalar if m = 1). The result is an array of size(nn,m) which is not a scalar.
In other words, you can't reduce the number of rows in T by multiplying by something on the right.
You indicate that lt and temp1 are scalars, in which case TTT is a column vector, rounded to integers, which are indices for the values in vectors 'a' and b.
Answers (0)
See Also
Categories
Find more on Logical 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!