Understanding Matrix Addition and Initialization

5 vues (au cours des 30 derniers jours)
James Pistorino
James Pistorino le 23 Fév 2017
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 commentaires
James Pistorino
James Pistorino le 23 Fév 2017
Modifié(e) : James Pistorino le 24 Fév 2017
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 le 24 Fév 2017
Modifié(e) : David Goodmanson le 24 Fév 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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by