質問

suppose that we have following matrices

>> X=create_matrix1(B,20);
>> [U E V]=svd(X);

in other word we have matrix and we are going to do svd of this matrix,then it is clear that following thing

z=vertcat(U(:,1),U(:,2),U(:,3));

dimension of this vector is

[m,n]=size(z)

m =

   825


n =

     1

while following thing

z1=vertcat(U(:,1:3));
[m,n]=size(z1)

m =

   275


n =

     3

so how can i fix this?thanks in advance EDITED: i want to concatenate for instance first d left and right matrix column using vertcat function

役に立ちましたか?

解決

You don't need a loop if you use reshape:

cols = [1:3];
z1 = reshape(U(:,cols), numel(U(:,cols)), 1);

You can also use this for non-consecutive columns, for example:

cols = [1 2 4 7];

Example:

A = [1 2 3;
     4 5 6;
     7 8 9]

cols = [1:2];
B = reshape(A(:,cols), numel(A(:,cols)), 1)

The output is:

A =

   1   2   3
   4   5   6
   7   8   9

B =

   1
   4
   7
   2
   5
   8

他のヒント

Try:

startRange = 1;
StopRange = 5;
for ii = startRange:stopRange
    col=U(:,ii)
    newmat = [newmat; col]
end
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top