loop over a cell and combine cell columns into one column
Show older comments
i have a cell array e.g
[1,10,18,24,31,40,0] [] 2.0673943 2.0874443 2.1595383 2.2108727 2.2004662 2.1298561 []
[2,11,19,25,32,41,49,-1] [] 2.5844460 1.4922142 1.9188881 2.1945801 2.1078224 2 2.0430222
[3,12,20,26,33,43,-1] [] 2.4619789 2.1192665 2.1591911 2.2104111 2.2032127 2.1415558 []
[4,13,21,27,34,-1] [] 2.7252617 1.4234924 1.8084259 1.9428711 2.0691185 [] []
i want to take every column and combine them together into a row vector into the 2nd column of my cell.
i did this but i cant find my mistake. my code takes every column and combines it into the 2nd column but in the next cell he takes the previous ones too.
for i = 1:length(element_row)
for k = 1:length(element_row{i,1})
Abstand = element_row{i,k+1};
row = [row,Abstand];
element_row{i,2} = row;
end
my output is:
[1,10,18,24,31,40,0] [2.0673943,2.0874443,2.1595383,2.2108727,2.2004662,2.1298561] 2.0673943 2.0874443 2.1595383 2.2108727 2.2004662 2.1298561 []
[2,11,19,25,32,41,49,-1] 1x13 single 2.5844460 1.4922142 1.9188881 2.1945801 2.1078224 2 2.0430222
[3,12,20,26,33,43,-1] 1x19 single 2.4619789 2.1192665 2.1591911 2.2104111 2.2032127 2.1415558 []
[4,13,21,27,34,-1] 1x24 single 2.7252617 1.4234924 1.8084259 1.9428711 2.0691185 [] []
but i want
[1,10,18,24,31,40,0] [2.0673943,2.0874443,2.1595383,2.2108727,2.2004662,2.1298561] 2.0673943 2.0874443 2.1595383 2.2108727 2.2004662 2.1298561 []
[2,11,19,25,32,41,49,-1] [2.5844460,1.4922142,1.9188881,2.1945801,2.1078224,2,2.0430222] 2.5844460 1.4922142 1.9188881 2.1945801 2.1078224 2 2.0430222
[3,12,20,26,33,43,-1] [2.4619789,2.1192665,2.1591911,2.2104111,2.2032127,2.1415558] 2.4619789 2.1192665 2.1591911 2.2104111 2.2032127 2.1415558 []
[4,13,21,27,34,-1] [2.7252617,1.4234924,1.8084259,1.9428711,2.0691185] 2.7252617 1.4234924 1.8084259 1.9428711 2.0691185 [] []
Accepted Answer
More Answers (0)
Categories
Find more on Cell 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!