last number is out of matrix range range
2 次查看(过去 30 天)
显示 更早的评论
Hi guys,
I need your help with this problem please, n1=492;n2=354;% first and last elements of x X=n1:(n2-n1)/(length(x)*1.25):n2; where x=[492 486 483 476 474 474 472 468 466 460 456 456 454 452 444 440 438 432 428 424 420 418 414 411 408 400 388 374 354];
the problem is that the last element of X(X(end)=3.549517241379310e+002) will be a little bit greater than n2= 354 ( the last element of x) is there any way to fix this problem to get (X(end)=n2=x(end))
0 个评论
回答(3 个)
Image Analyst
2013-9-23
Can't you just use linspace???
outputArray = linspace(startingValue, endingValue, numberOfElements);
0 个评论
David Sanchez
2013-9-23
you can round the last element:
n1=492; n2=354; x = ones(20,1); X=n1:(n2-n1)/(length(x)*1.25):n2;
X2 = floor(X);
X2 =
Columns 1 through 9
492 486 480 475 469 464 458 453 447
Columns 10 through 18
442 436 431 425 420 414 409 403 398
Columns 19 through 26
392 387 381 376 370 365 359 354
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!