【问题标题】:ploting 3d graph in matlab?在matlab中绘制3d图形?
【发布时间】:2010-03-14 00:04:44
【问题描述】:

我目前是初学者,我正在使用 matlab 进行数据分析。我有一个文本文件,第一行的数据格式如下: 时间;波高 1;波高 2;....... 我的列直到波高 19,行总数为 4000 行。

第一列中的数据是以秒为单位的时间。从第 2 列开始,为以米为单位的波高标高。目前,我想要求 matlab 绘制一个 3d 图,其中 x 轴为时间,y 轴为波浪高程,波浪高程对应于从 1 到 19 的波高数,即第 2 列第 10 行中的数据具有假设 8m 对应于波高 1 和第 1 列第 10 行的时间。

我尝试了以下方法:

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,:);

但每次我尝试绘制它们时,for 循环 wi 工作正常,但对于 r=a(l,:);,绘图要么只给我最后一次数据,但我想要文件中的所有数据成为情节。

有没有办法我可以做到这一点。很抱歉,这有点令人困惑,但如果有人能帮助我,我将非常感激。

谢谢!!!!!!!!!!

【问题讨论】:

    标签: matlab plot


    【解决方案1】:

    一旦您像在代码中那样加载数据后,变量a 应该是一个 4000×20 数组。然后,您可以通过几种不同的方式创建 3-D 图。您可以使用函数PLOT3 创建一个 3-D 线图,为波浪高程数据的每一列绘制一条线:

    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
    

    另一种以 3-D 形式绘制数据的方法是制作网格图或曲面图,分别使用函数 MESH 或 SURF。这是一个例子:

    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
    

    【讨论】:

      【解决方案2】:

      我不太明白你的函数是做什么的,例如,我没有看到任何绘图命令。

      以下是我尝试根据您的规格制作 3D 绘图的方法:

      %# 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')
      

      【讨论】:

        【解决方案3】:

        或者,您可以尝试gnuplot。快速、免费且相对易于使用。我用它为数百万行的数据集生成热图。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-03-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多