tags:

views:

414

answers:

3

Hello,

I am currently a begineer, and i am using matlab to do a data analysis. I have a a text file with data at the first row is formatted as follow: time;wave height 1;wave height 2;....... I have column until wave height 19 and rows total 4000 rows.

Data in the first column is time in second. From 2nd column onwards, it is wave height elevation which is in meter. At the moment I like to ask matlab to plot a 3d graph with time on the x axis, wave elevation on the y axis, and wave elevation that correspond to wave height number from 1 to 19, i.e. data in column 2 row 10 has a let say 8m which is correspond to wave height 1 and time at the column 1 row 10.

I have try the following:

clear;    
filename='abc.daf';    
path='C:\D';

a=dlmread([path '\' filename],' ', 2, 1);

[nrows,ncols]=size(a);

t=a(1:nrows,1);%define t from text file

for i=(1:20),    
   j=(2:21);    
end

wi=a(:,j);

for k=(2:4000),    
   l=k;    
end

r=a(l,:);

But everytime i use try to plot them, the for loop wi works fine, but for r=a(l,:);, the plot only either give me the last time data only but i want all data in the file to be plot.

Is there a way i can do that. I am sorry as it is a bit confusing but i will be very thankful if anyone can help me out.

Thank you!!!!!!!!!!

A: 

I don't quite understand what your function does, for example, I do not see any plot command.

Here's how I'd try to make a 3D plot according to your specs:

%# Create some data - time from 0 to 2pi, ten sets of data with frequency 1 through 10.
%# You would just load A instead (I use uppercase just so I know that A is a 2D array, 
%# rather than a vector)
x = linspace(0,2*pi,100)';%#' linspace makes equally spaced points
w = 1:10;
[xx,ww]=ndgrid(x,w); %# prepare data for easy calculation of matrix A
y = ww.*sin(xx.*ww);
A = [x,y]; %# A is [time,data]

%# find size of A
[nRows,nCols] = size(A);

%# create a figure, loop through the columns 2:end of A to plot
colors = hsv(10);
figure,
hold on,

for i=1:nCols-1,

%# plot time vs waveIdx vs wave height
plot3(A(:,1),i*ones(nRows,1),A(:,1+i),'Color',colors(i,:)),

end

%# set a reasonable 3D view
view(45,60)

%# for clarity, label axes
xlabel('time')
ylabel('wave index')
zlabel('wave height')
Jonas
A: 

Once you load your data as you do in your code above your variable a should be a 4000-by-20 array. You could then create a 3-D plot in a couple of different ways. You could create a 3-D line plot using the function PLOT3, plotting one line for each column of wave elevation data:

t = a(:,1);   %# Your time vector
for i = 2:20  %# Loop over remaining columns
  plot3(t,(i-1).*ones(4000,1),a(:,i));  %# Plot one column
  hold on;    %# Continue plotting to the same axes
end
xlabel('Time');            %# Time on the x-axis
ylabel('Wave number');     %# Wave number (1-19) on y-axis
zlabel('Wave elevation');  %# Elevation on z-axis

Another way to plot your data in 3-D is to make a mesh or surface plot, using the functions MESH or SURF, respectively. Here's an example:

h = surf(a(:,1),1:19,a(:,2:20)');  %'# Plot a colored surface
set(h,'EdgeColor','none');  %# Turn off edge coloring (easier to see surface)
xlabel('Time');             %# Time on the x-axis
ylabel('Wave number');      %# Wave number (1-19) on y-axis
zlabel('Wave elevation');   %# Elevation on z-axis
gnovice
A: 

Or, you could try gnuplot. Fast, free and relatively easy to use. I use it to generate heat maps for datasets in the millions of rows.

Nate

related questions