Understanding Matrix Addition and Initialization
조회 수: 5 (최근 30일)
이전 댓글 표시
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
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 Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!