Index out of bounds in for cycle (MATLAB)

Ok, I'm having a problem (probably a newbie problem) but here it goes:

for i=1:1:16; h=10^(-i); yDFC2(i)=(1/(2*1*h(i)))*(-1*valX+valX); end err2=abs(fDX(x1)-yDFC2); loglog(h,err2,'b-');

Every time I run this code, it gives me the following error:

Attempted to access h(2); index out of bounds because numel(h)=1

valX is a variable calculated by determining the image of a function that has been inputted by the user; fDX is the derivative of that function (both are working well).

This is meant to plot the spacing (h) vs the error in central finite differences (CFD). The formula inside the for cycle is the 1st order derivative calculated by CFD for n=2.

The spacing needs to be in increments of 10^(-i).

If anyone could help me figure this out, I'd be very thankful.

-------------Problems Reply------------

If you do

h = 10.^(-(1:1:16));

outside of the for loop, you can accress h(i) correctly inside. The problem is that you create a scalar h for each pass.

Category:matlab Views:1 Time:2011-11-29
Tags: matlab

Related post

  • What is wrong with my Matlab code? Index out of bounds 2011-08-08

    I'm trying to read in a text file that contains nmea strings! But I get ??? Attempted to access y(1); index out of bounds because numel(Longitude)=0. Error in ==> filter at 16 Loc(:,i)=coordinates(x(i),y(i))'; filter.m clear all A=textread('xxx\x.

  • index out of bounds in matlab 2012-04-18

    I am not able to get how to run it, can anyone help me on this please. I am receiving this error : K>> [minutiae_valid]=postprocess_TICO(B,im,~K) ??? Attempted to access wind(273,386); index out of bounds because size(wind)=[368,385]. Error in

  • Array index out of bound in C 2009-03-22

    Why does C differentiates in case of array index out of bound #include <stdio.h> int main() { int a[10]; a[3]=4; a[11]=3;//does not give segmentation fault a[25]=4;//does not give segmentation fault a[20000]=3; //gives segmentation fault return

  • How can I find the location of a "List index out of bounds" error in Delphi 2009-07-28

    In Delphi 2009, my program now produces a "List index out of bounds" error. It generates a popup box: I'm using the "Debug" Build Configuration that has all the Runtime error checking turned on. But this does not capture the error before it happens.

  • AppController error: Index out of bounds 2009-08-19

    I overrode the following target in my TFS build file to run various tasks that set up databases, import data, etc., etc. in Visual Studio 2008 - the aim was to stop only the website associated with an application pool on the server instead of stoppin

  • Java Array Index out of Bounds 2010-07-11

    OK so I seem to be getting an Array Index out of Bounds error in a part of my code. Specifically in lines 85-102... My code: http://www.sosos.pastebin.com/f0JQBWui I just want it to check for blocked tiles AHEAD of time that way my sprite doesn't mov

  • how to handle table index out of bound for iphone 2010-07-31

    when i scroll table view data then i am getting this error ** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (5) beyond bounds (5)' 2010-07-31 12:24:50.297 Wat2Eat[3105:207] Stack: ( how

  • Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 1 beyond bounds [0 .. 0]' 2010-11-10

    i'm receiving the following errors, very new to iphone dev and objective C. I am very much willing to send over my project for someone to have a look, i'm running in circles and have no idea what to do next! 2010-11-10 19:38:07.822 iShisha[2698:207]

  • List index out of bounds, adding frame delphi 2010-11-16

    I tried to search for my error, read some topics, but I couldn't find a hint why it would be happening. If someone could help me to at least get some hint of how I can check out what is happening, so I`m able to fix it, it would be greatly appreciate

  • [NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array from AVURLAsset 2010-12-09

    I tried with following code to merge the audios. AVMutableComposition* composition = [AVMutableComposition composition]; AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL:audioURL options:nil]; AVURLAsset* audioAsset1 = [[AVURLAsset alloc]initW

  • index 0 beyond bounds for empty array error 2011-02-02

    I don't understand on how to debug this error message: 2011-02-01 20:45:56.151 NeMe[3206:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array' ***

  • [NSArray subarrayWithRange:]: index 9779 beyond bounds 2011-03-07

    I am getting the error: *** -[NSArray subarrayWithRange:]: index 9779 beyond bounds [0 .. 9776]' *** and I am not sure how to fix it. If you could tell me that would be great! NSArray *keys = [NSArray arrayWithObjects:@"type", @"name", @"street", @"a

  • cursor index out of bounds "index 0 requested: with size 0" 2011-03-15

    I am getting cursor index out of bounds "index 0 requested: with size 0" error when I search my database for something. The item I am searching for in my database does not exist currently and i am aware of that but how do i handle a query where the i

  • Error message: "index 1 beyond bounds" 2011-04-19

    I'm just a rookie and I cant seem to find the error. It's a piece of code for scaling, rotating and moving a UIImageView. I can move the UIImageView but when I try to rotate or scale the UIImageView it just crashes. I did set the setMultipleTouchEnab

  • Extracting a string with substringWithRange: gives "index out of bounds" 2011-05-18

    When I try to extract a string from a larger string it gives me a range or index out of bounds error. I might be overlooking something really obvious here. Thanks. NSString *title = [TBXML textForElement:title1]; TBXMLElement * description1 = [TBXML

  • QTMovie index of out bounds exception when trying to addImage:forDuration:withAttributes 2011-06-07

    I am trying to create a movie in Cocoa using QTKit. This movie should consist of a bunch of NSImage's that I have created. I'm running into some problems with this. The overall problem is that the movie isn't created. I get a file which appears to be

  • Delphi 7 IDE - Index out of bounds in list read access 2011-06-22

    One of my delphi projects produces this error message when closing the IDE. Note This is not the same as 'List Index out of bounds(0)' error. Then it always shows another error: 'Invalid Pointer Operation' Any ideas how i could locate where it is com

  • Problem using NSRange: Index out of bounds 2011-06-29

    I am trying to detect website URL's in my string and then doing some attribution string stuff like bolding it etc. My regex is defined as: static NSRegularExpression *websiteRegularExpression; static inline NSRegularExpression * WebsiteRegularExpress

  • getting exception "index 0 beyond bounds for empty array"? 2011-07-12

    i am getting start date and end date from user via date pickerview. when user scroll the pickerview in speed then it crashes there and gives me this exception. so whats the solution? [ NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty a

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.132 (s). 11 q(s)