matrix to vector matrix ?

1 回表示 (過去 30 日間)
ubeyd yuruk
ubeyd yuruk 2015 年 4 月 2 日
編集済み: Stephen23 2015 年 4 月 2 日
ok i know reshape works for this actually..but i want to reshape my matrix like this a = [111 ,101, 100]
a = [111101100]
reshape makes it like : a= [111100110]
so what i want to do is actually put all vectors behind each other..like first row then second row then third so on..is there anyway to do that ?

採用された回答

Mohammad Abouali
Mohammad Abouali 2015 年 4 月 2 日
a = [111 ,101, 100];
num2str(a,'%d')
ans =
111101100
  1 件のコメント
ubeyd yuruk
ubeyd yuruk 2015 年 4 月 2 日
thanks man you just saved my day

サインインしてコメントする。

その他の回答 (1 件)

Stephen23
Stephen23 2015 年 4 月 2 日
編集済み: Stephen23 2015 年 4 月 2 日
The solution is very simple!
MATLAB is column-major, so it works down the columns first, then the along the rows. So if you want to reshape along the rows first, you can simply transpose the input matrix before doing the reshape:
>> a = [1,1,1;1,0,1;1,0,0]
a =
1 1 1
1 0 1
1 0 0
>> reshape(a.',1,[])
ans =
1 1 1 1 0 1 1 0 0
And that's it! Just one little transpose of the input matrix makes this work. There is no need for a slow string conversion. Note that if the input array is already a character array, this method will still work:
>> a = ['111';'101';'100']
a =
111
101
100
>> reshape(a.',1,[])
ans =
111101100

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by