Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Data storage in a for loop in matlab

  1. Mar 23, 2010 #1

    I'm trying to write a program, to show the vector field of a linear simple wave in shallow water. First, determining the position of a particle i run into a problem when trying to store the data in a vector/array. The equation for this is given below. In this particular case everything is kept constant except the water depth h

    for h = 0.1: 0.1: 3

    I get the following error:

    ??? Attempted to access x(0.1); index must be a positive integer or logical.

    Help is much appreciated...

  2. jcsd
  3. Mar 23, 2010 #2
    I have realized that the index must be an integer. The increments need to be at least 0.1 so is there another way to store the x-values
  4. Mar 23, 2010 #3
    You will need two vectors, one for x and one for h. This will work if all the other values are scalars:

    h = 0.1:0.1:3;
    x = xi + H/2 * cosh(omega./sqrt(g*h).*(zeta+h)) ./ sinh(omega./sqrt(g*h).*h) .* sin(omega*t - omega./sqrt(g*h).*xi);

    As an example, in order to plot x versus h, you will just use plot(x,h).
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Threads - Data storage loop Date
Mathematica Chisquare fit to multiple data sets Aug 4, 2017
Matlab Plotting Data Mar 18, 2017
Matlab How to extract data from existing JPEG/TiFF graph? Oct 27, 2016
Matlab Data Analysis: Observation Model Problem Oct 17, 2016
Data Storage in Mathematica Sep 21, 2008