Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在matlab中绘制三维图形?_Matlab_Plot - Fatal编程技术网

在matlab中绘制三维图形?

在matlab中绘制三维图形?,matlab,plot,Matlab,Plot,我目前是一名初学者,我正在使用matlab进行数据分析。我有一个文本文件,第一行的数据格式如下: 时间波高1;波高2;。。。。。。。 我有一列,直到波高19,总共4000行 第一列中的数据是以秒为单位的时间。从第2列开始,是波高高程,单位为米。目前,我想让matlab绘制一个3d图形,其中x轴上有时间,y轴上有波浪高程,波浪高程对应于波高数1到19,即第2列第10行中的数据有一个8m,对应于波高1和第1列第10行的时间 我尝试了以下方法: clear; filename='abc.daf

我目前是一名初学者,我正在使用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=al,:;,“仅绘图”要么只给我上一次的数据,要么我想打印文件中的所有数据

我有办法做到这一点吗。我很抱歉,因为这是一个有点混乱,但我将非常感谢,如果有人可以帮助我


谢谢你

我不太了解您的函数的功能,例如,我没有看到任何plot命令

以下是我如何根据您的规格制作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')

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

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
在三维中绘制数据的另一种方法是分别使用函数或进行网格或曲面绘制。下面是一个例子:

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
或者,你可以试试。快速、免费且相对易于使用。我使用它为数百万行的数据集生成热图