how to make a row into a one element

3 ビュー (過去 30 日間)
zeezo 2016 年 5 月 9 日
コメント済み: Ahmet Cecen 2016 年 5 月 9 日
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 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
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 件のコメント
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 件のコメント
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



Find more on Multidimensional Arrays in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by