필터 지우기
필터 지우기

how to make a row into a one element

조회 수: 3 (최근 30일)
zeezo
zeezo 2016년 5월 9일
댓글: Ahmet Cecen 2016년 5월 9일
Hi,
I have this matrix a=[1 4 5 3 5; 2 5 7 0 8; 3 5 7 2 9]
and I wand to make each row into one element to become like this
a=[14535; 25708; 35729]
  댓글 수: 1
zeezo
zeezo 2016년 5월 9일
Thanks very much. in fact, I need for a time matrix and the code that you proved me does not work.
I have this matrix a 00:01:17
06:14:19
06:29:01
06:41:08
06:53:34
and its size is 8*5. how can

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

답변 (2개)

CS Researcher
CS Researcher 2016년 5월 9일
Try this:
N = size(a,2);
powerVector = 10.^[N-1:-1:0]';
requiredVector = a*powerVector;
Hope this helps!
  댓글 수: 2
zeezo
zeezo 2016년 5월 9일
Thanks very much. in fact, I need for a time matrix and the code that you proved me does not work.
I have this matrix a 00:01:17
06:14:19
06:29:01
06:41:08
06:53:34
and its size is 8*5. how can
Image Analyst
Image Analyst 2016년 5월 9일
What does
whos a
show? Is it a cell array or a character array?

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


Ahmet Cecen
Ahmet Cecen 2016년 5월 9일
편집: Ahmet Cecen 2016년 5월 9일
The other answer will only work for a very limited set of problems, and will break with even the slightest change, like having a number bigger than 10 as an element in the array. You can still use it if it works for you, but a much more robust way is below:
a = mat2str(a);
a = strrep(a,' ','');
a = str2num(a);
  댓글 수: 2
zeezo
zeezo 2016년 5월 9일
Thanks Ahmet. but I need the matrix size to become 1*3 NOT 1*19
Ahmet Cecen
Ahmet Cecen 2016년 5월 9일
It is indeed 1x3 for me. You are leaving out something.
Name Size Bytes Class Attributes
a 3x1 24 double

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by