How can I create a loop for transpose row vector to column vector

조회 수: 10 (최근 30일)
Hi guys!
I have a data 4624X12 and i need transpose every line to columns, to getting a 55488X1 matrix.
I tried the following loop:
j=1; [row,col]=size(data); for i=1:row M(j)=data(i,:)'; j=j+1 end
This error appier in this situation: "??? In an assignment A(I) = B, the number of elements in B and I must be the same"
Tks every budy!

채택된 답변

Roger Stafford
Roger Stafford 2013년 5월 14일
Your words "transpose every line to columns" hint that you wish the rows to remain contiguous within the single column. If so, do this:
M = data.';
M = M(:);
  댓글 수: 1
Gustavo Oliveira
Gustavo Oliveira 2013년 5월 14일
Tks Roger! This really works, I am new in this thing and I'm always complicating everythink.

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

추가 답변 (2개)

Shashank Prasanna
Shashank Prasanna 2013년 5월 14일

Jan
Jan 2013년 5월 14일
The error message explains exhaustively, why M(j)=data(i,:)' must fail: There is a vector on the left side, but a scalar on the right side. Obviously you cannot assign the values of a vector to one scalar.
Roger's answer solves the problem efficiently.

카테고리

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