Understanding Matrix Addition and Initialization

조회 수: 5 (최근 30일)
James Pistorino
James Pistorino 2017년 2월 23일
편집: James Pistorino 2017년 2월 24일
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
James Pistorino
James Pistorino 2017년 2월 23일
편집: James Pistorino 2017년 2월 24일
I edited this to show more code. This code is dealing with pixel points. So, the first part separates the pixels into x and y values stored in matrix/vectors a and b respectively. Now I am seeing, that TTT could be a matrix/vector into a or b. That is probably the issue. Thanks.
David Goodmanson
David Goodmanson 2017년 2월 24일
편집: David Goodmanson 2017년 2월 24일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by