Hi, I want to create a new cell array AAAA with the following code.
GGG= {[1 2 1 2 1 1 1 2 3 4 4 5 4 5 5 4 4 5 5 4 6 6 6 6 6 6 3 3 9 9 3 9 9 9; 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 ],[1 1 1 1 1 2 3 2 2 3 4 4 4 5 5 4 4 5 4 6 3 6 6 3 6 3 6 3 3 9 3 9 9 9 9; 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175]};tt = [20 20 20 20 20 20 20 20 20];GGG1= [1 2 1 2 1 1 1 2 3 4 4 5 4 5 5 4 4 5 5 4 6 6 6 6 6 6 3 3 9 9 3 9 9 9; 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 ];for i=1:numel(GGG)AAAA{i}=[GGG1(1,:);GGG1(2,end)+cumsum(diff([0,GGG(2,:)]))];end
In AAAA I have the saem number of cell of GGG.
Considering just the first cell of GGG.the first raw of AAA is made merging the first raw GGG1 with the first raw of GGG. the second raw of AAA is made by the second raw of GGG1 and then summing each difference (between an element and is preceeding) of the second raw of GGG. As indicated in the formula
cumsum(diff([0,GGG(2,:)]))
I dont know why but I obtain this error:
Index in position 1 exceeds array bounds (must not exceed 1).Error in Untitled555555 (line 10)AAAA{i}=[GGG1(1,:);GGG1(2,end)+cumsum(diff([0,GGG(2,:)]))];
Result for the first cell should be :
AAAA= [1 2 1 2 1 1 1 2 3 4 4 5 4 5 5 4 4 5 5 4 6 6 6 6 6 6 3 3 9 9 3 9 9 9 1 2 1 2 1 1 1 2 3 4 4 5 4 5 5 4 4 5 5 4 6 6 6 6 6 6 3 3 9 9 3 9 9 9; 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200 205 210 215 220 225 230 235 240 245 250 255 260 265 270 275 280 285 290 295 300 305 310 315 320 325 330 335 340]
could someone help me?
Best Answer