# Making a contour plot in MALAB

 Register Blogs Members List Search Today's Posts Mark Forums Read

 July 18, 2008, 15:53 Making a contour plot in MALAB #1 Mick Guest   Posts: n/a I need help with matlab. This is my error ??? Attempted to access Z(0,0); index must be a positive integer or logical. My data is 3 columns separated by a tab space. The first column is the x , the second column is the y, and the third is the z. There is 3240 numbers in each column (36 * 95) I don't think that the z is the only error and i know that MATLAB begins from 1 not zero. My data looks like this: 0 1 3 0 2 8 ... ... ... 35 94 4 % Open file, fid keeps track of it. fid = fopen('contourplot'); % Scan all rows and interpret as three integers separated by space C = textscan(fid, '%d %d %d', 'CollectOutput', 0); % Done with file, close it fclose(fid); % Assign the data to vectors for easier access x = C{1}; y = C{2}; z = C{3}; % Get data to determin how big matrix to zero maxx = max(x); maxy = max(y); samples = length(z); % zero it Z = zeros(maxx, maxy); % assign the right values from z to the right % coordinates in the matrix for i = 1:samples Z(x(i), y(i)) = z(i); end % Settings for the gradient lowest = 0; highest= 2; levels = 20; % Get uniform distribution of levels between highest and lowest v = lowest : (highest - lowest) / levels : highest; % Draw the contour contour(Z, v); % Set the axis [xMin xMax yMin yMax] axis([0 35 0 94]);

 July 21, 2008, 14:06 Re: Making a contour plot in MALAB #2 UnderwaterAlex Guest   Posts: n/a This is a CFX forum, not matlab. Maybe someone can help you here, but I bet you'd have better luck here: http://www.mathworks.com/matlabcentral/newsreader/ I don't particularly understand what you are asking, but the problem is that somewhere a function is trying to access Z(0,0) and my guess is that it is in the drawing of the contour. From my limited experience to create a contour plot successfully in Matlab, the easiest was is to use meshgrid to create the location variables. Probably the first part of my response (posting to a matlab forum) is much more helpful than the second part. Best of luck -Alex