create intervals of equal length but sequential

3 次查看(过去 30 天)
Hi, I would like to create intervals of equal length but sequential. Let me explain better with an example:
I have a duration of 630 seconds, punctuated by every 90 seconds. I have already created a vector indicating the instants [90,180,270,360,450,540,630]. at this point I would like to create a container of intervals, therefore of the type: [0,90], [90, 180] etc. Then put them in a for loop and perform operations inside each of them. in practice I should generate a value through other orperations from the first for within the interval [0.90] to pass to the second interval [90.180] and so on. How can this be done? Thank you all
  8 个评论
Voss
Voss 2022-2-12
"How can I make the first line of a vector contain ids from 0 to 90, the second line to contain those from 90 to 180 and what goes for all 7 ranges? so that it can then index that vector in x and use it to compute "macchine""
This creates a matrix of indexes (-1) with 7 rows:
p = 0:630;
ti = (0:p(end)/90)*90;
inductionID = {'ID1' 'ID2' 'ID3' 'ID4'};
idx = zeros(numel(ti)-1,91);
for ii = 1:numel(ti)-1
idx(ii,:) = ti(ii):ti(ii+1);
end
disp(idx);
Columns 1 through 37 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 Columns 38 through 74 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 Columns 75 through 91 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
But you want a matrix of IDs with the same size as that, right? It's not clear to me how the traci function inductionloop.getLastStepVehicleNumber() will "know" which iteration of the ii loop the code is in when the function is called, but maybe this?
p = 0:630;
ti = (0:p(end)/90)*90;
inductionID = {'ID1' 'ID2' 'ID3' 'ID4'};
% can pre-compute matrix idx like above:
idx = zeros(numel(ti)-1,91);
for ii = 1:numel(ti)-1
idx(ii,:) = ti(ii):ti(ii+1);
end
% or you can compute each row of idx in the ii loop below
% (and idx doesn't need to be a matrix if you only need one
% row at a time)
for i = 1:1%duration
% traci.simulation.step();
macchine = zeros(numel(inductionID),numel(p));
somme = zeros(numel(inductionID),numel(ti)-1);
for ii = 1:numel(ti)-1
for n = 1: length(inductionID)
% this assumes that the function
% traci.inductionloop.getLastStepVehicleNumber(inductionID{n})
% returns a single (scalar) value, which is then assigned to
% the 91 columns idx(ii,:)+1 of the nth row of macchine:
% macchine(n,idx(ii,:)+1) = traci.inductionloop.getLastStepVehicleNumber(inductionID{n});
% demonstration with random number:
macchine(n,idx(ii,:)+1) = randn();
end
somme(:,ii) = sum(macchine(:,idx(ii,:)+1),2); %I want to sum for each ii, the values ​​contained in the whole considered interval, so for example for ii = 1 I would like the sum of all the values ​​calculated in [0,1 ... 90] and so on for the other ii
end
disp('macchine:');
disp(macchine);
disp('somme:');
disp(somme);
disp(' ');
disp('now each element of somme is the same as 91 times the corresponding element of macchine');
disp('(from column 91, 181, etc.), since each element of macchine is repeated 91 times');
disp('(ignoring the overlapping at the interval boundaries):');
disp(' ');
disp('91*macchine(:,1:90:end-1)');
disp(91*macchine(:,1:90:end-1));
disp(' ');
disp('max difference is very close to 0 (not exactly 0 due to floating-point precision):');
disp('max(abs(91*macchine(:,1:90:end-1) - somme))');
disp(max(abs(91*macchine(:,1:90:end-1) - somme)));
end
macchine:
Columns 1 through 22 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 Columns 23 through 44 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 Columns 45 through 66 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 Columns 67 through 88 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 -0.3613 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 3.1607 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 -0.1146 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 0.9140 Columns 89 through 110 -0.3613 -0.3613 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 3.1607 3.1607 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 -0.1146 -0.1146 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 0.9140 0.9140 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 Columns 111 through 132 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 Columns 133 through 154 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 Columns 155 through 176 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 1.6072 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 0.9826 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 1.4423 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 -0.3801 Columns 177 through 198 1.6072 1.6072 1.6072 1.6072 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 0.9826 0.9826 0.9826 0.9826 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 1.4423 1.4423 1.4423 1.4423 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 -0.3801 -0.3801 -0.3801 -0.3801 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 Columns 199 through 220 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 Columns 221 through 242 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 Columns 243 through 264 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 Columns 265 through 286 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 -1.6227 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -0.2097 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 0.6498 0.6498 0.6498 0.6498 0.6498 0.6498 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.6819 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 Columns 287 through 308 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 Columns 309 through 330 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 Columns 331 through 352 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 Columns 353 through 374 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 0.0823 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.2502 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 0.8920 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -0.4619 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 Columns 375 through 396 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 Columns 397 through 418 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 Columns 419 through 440 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 Columns 441 through 462 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 -1.2439 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -1.6587 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 1.2606 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 -2.8382 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 Columns 463 through 484 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 Columns 485 through 506 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 Columns 507 through 528 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 Columns 529 through 550 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.2061 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 -0.0676 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 -3.2983 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.9261 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 Columns 551 through 572 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 Columns 573 through 594 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 Columns 595 through 616 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 Columns 617 through 631 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.5447 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.4747 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.5409 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025
somme:
-32.8765 146.2533 -147.6612 7.4889 -113.1987 18.7519 49.5670 287.6273 89.4122 -19.0834 -113.7681 -150.9387 -6.1539 43.2006 -10.4270 131.2497 59.1327 81.1716 114.7163 -300.1472 49.2251 83.1714 -34.5846 -62.0526 -42.0324 -258.2753 84.2730 0.2238
now each element of somme is the same as 91 times the corresponding element of macchine
(from column 91, 181, etc.), since each element of macchine is repeated 91 times
(ignoring the overlapping at the interval boundaries):
91*macchine(:,1:90:end-1)
-32.8765 146.2533 -147.6612 7.4889 -113.1987 18.7519 49.5670 287.6273 89.4122 -19.0834 -113.7681 -150.9387 -6.1539 43.2006 -10.4270 131.2497 59.1327 81.1716 114.7163 -300.1472 49.2251 83.1714 -34.5846 -62.0526 -42.0324 -258.2753 84.2730 0.2238
max difference is very close to 0 (not exactly 0 due to floating-point precision):
max(abs(91*macchine(:,1:90:end-1) - somme))
1.0e-12 * 0.1279 0.1563 0.1705 0.2700 0.4547 0.7390 0.0355
But again, notice column 91 of macchine gets the values from the second time it is used (when ii == 2) and the value set the first time (when ii == 1) was overwritten and is lost. Same for 181, etc.
Marco Carapellese
Marco Carapellese 2022-2-13
"But you want a matrix of IDs with the same size as that, right? It's not clear to me how the traci function inductionloop.getLastStepVehicleNumber() will "know" which iteration of the ii loop the code is in when the function is called, but maybe this?"
practically the inductionloop.getLastStepVehicleNumber () function calculates the number of vehicles in each instant of time (which is the one to set) on each induction id. This is why I wanted to calculate it for all 630 instances, but divided by intervals of 90 which I would like to add together to finish.

请先登录,再进行评论。

回答(2 个)

Steven Lord
Steven Lord 2022-2-11
So into which interval should a value of exactly 90 fall? Interval 1, interval 2, or both?
I think that depending on what operations you want to perform the discretize, groupsummary, and/or grouptransform functions may be of use to you.
  1 个评论
Marco Carapellese
Marco Carapellese 2022-2-11
So, the instant 90 would serve me in the first interval, that is [0.90], while I would also like to perform a sudden action that however starts for example from the interval [180.270] in addition to all the other operations that I tried to indicate before . Thanks again

请先登录,再进行评论。


Image Analyst
Image Analyst 2022-2-12
You can process the array in chunks of 7 elements. I assume that the first chunk will be times less than or equal to 90, the second chunk will correspond to times in the 90.0000001 to 180 range, and so on
for k = 1 : length(vec)
index1 = k;
index2 = min(k, k+6);
thisData = vec(index1 : index2);
% Now do something with thisData
end
If that's not the situation, like maybe you have both a time vector and a signal vector that corresponds to a measurement made at the corresponding time, then try this
for k = 1 : length(timeVector)
indexes = timeVector >= (k-1) * 90 & timeVector <= k * 90;
thisData = signalVector(indexes);
% Now do something with thisData
end

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by