Matrix row cell concatenation

조회 수: 8 (최근 30일)
Ahsan
Ahsan 2019년 7월 20일
댓글: Stephen23 2023년 4월 11일
Hello,
I have a matrix and I would like to combine its row cells as an array of the matrix.
Ex:a
1 2 3
4 5 6
7 8 9
result:b
123
456
789
I tried a solution to from this link:
a = [ 8 1 6 ; 1 2 3 ; 4 5 6 ]
[l c ] = size (a) ;
b = cell (l,1);
for i =1 : l
b {i,: } = [ a(i,1) a(i,2) a(i,3) ] ;
end
but I get the out put as
ans =
[1x3 double]
[1x3 double]
[1x3 double]
any help would be appreciated. Thnx
  댓글 수: 4
Ahsan
Ahsan 2019년 7월 21일
and I am trying to achieve 1.[123; 456; 789], a 3-by-1 column vector of 3-digit numbers?
Stephen23
Stephen23 2023년 4월 11일
M = [1,2,3;4,5,6;7,8,9];
V = M*[100;10;1]
V = 3×1
123 456 789

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

답변 (1개)

madhan ravi
madhan ravi 2019년 7월 20일
편집: madhan ravi 2019년 7월 20일
b = reshape(arrayfun(@(x)polyval(a(x,:),10),...
1:size(a,1),'un',0),[],1);
Wanted = cell2mat(b)
  댓글 수: 4
madhan ravi
madhan ravi 2019년 7월 20일
편집: madhan ravi 2019년 7월 22일
What more do you need ? Doesn't the below give what you want??
>> a = [1 2 3
4 5 6
7 8 9 ];
>> bb=num2cell(string(a),1);
>> b=str2double(strcat(bb{:}))
b =
123
456
789
>> size(b)
ans =
3 1 % 3 by 1 vector
>>
Andrew Sol
Andrew Sol 2023년 4월 11일
Here! That's what I need! Thank you!

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

카테고리

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