How do I concatenate cells in each row in a matrix?

1 Ansicht (letzte 30 Tage)
MS
MS am 15 Jul. 2016
Kommentiert: MS am 16 Jul. 2016
Dear Matlab users,
I need to cancat each row's cell in a matrix, For example: I have this matrix:
8 1 6
3 5 7
4 9 2
My goal is to have this form: 816, 357, 492.
I am beginner with matlab. I would be very grateful if you could help me. Thanks in advance.
  1 Kommentar
Stephen23
Stephen23 am 15 Jul. 2016
Bearbeitet: Stephen23 am 15 Jul. 2016
"My goal is to have this form: 816, 357, 492."
Can you please explain what you want: is this three numbers with values 816, 357, and 492, or three separate vector of integers {[8,1,6],[3,5,7],[4,9,2]}, or is this three strings {'816','357','492'}, or something else entirely?
Your description is not very clear what you want the output to be.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

AMAL targhi
AMAL targhi am 15 Jul. 2016
Bearbeitet: Guillaume am 15 Jul. 2016
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
  7 Kommentare
MS
MS am 15 Jul. 2016
@Stephen: yes sir, exactly i use octave, for that i am not sur about the solution that i have.
MS
MS am 16 Jul. 2016
@Guillaume and @ AMAL targhi thank you very much for your help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Andrei Bobrov
Andrei Bobrov am 15 Jul. 2016
Bearbeitet: Andrei Bobrov am 15 Jul. 2016
num2cell(a,2)
  1 Kommentar
MS
MS am 15 Jul. 2016
Bearbeitet: Guillaume am 15 Jul. 2016
Thank you very much for your help, however sir the size of my matrix id 100*16:
208 15 217 252 128 35 50 252 209 120 97 140 235 220 32 251
231 174 143 43 125 66 49 143 48 139 81 103 154 229 93 229
32 10 237 65 224 22 83 238 31 15 252 27 179 48 173 221
233 18 178 101 90 109 225 184 210 168 183 185 190 169 96 205
161 133 149 18 115 65 120 123 163 227 105 157 98 240 221 142
24 24 208 175 246 76 103 163 4 28.........
So by trying your method i have this result: operator *: nonconformant arguments (op1 is 100x16, op2 is 3x1) I would be very grateful sir if you could help me. Thanks in advance.

Melden Sie sich an, um zu kommentieren.

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by