如何让 MatLab 遍历 Excel 工作表中的行并在子图中绘制数据



我在Excel电子表格中有数据,我想将其导入MatLab以3D形式绘制。我希望为每行数据显示不同的图。这些行是 B3:P3 到 B74:P74。我认为 for 循环效果最好,但我无法正确获取语法以使其从数据开始到结束。

我所拥有的是混乱的,因为我一直在尝试不同的东西。这是我到目前为止所拥有的:

datasetstart = xlsread('data.xlsx', 'sheet', 'B3:P3');
datasetend = xlsread('data.xlsx', 'sheet', 'B74:P74');

%what are your x values 
%x = dataset(rows, columns) x&y are the locations of TCs
x = xlsread('data.xlsx', 'sheet', 'U3:U17');
y = xlsread('data.xlsx', 'sheet', 'V3:V17');
%specify grid points on mesh grid
v_x = linspace(-10,10,50);
v_y = linspace(-5,5,50);
%build 2D mesh
[xx,yy] = meshgrid(v_x,v_y); mesh(xx,yy,ones(50,50))
for time_loop = datasetstart:datasetend
%     subplot(x,y,time_loop); mesh(z,y,time_loop); title('works');
%     plot3(x,y,time_loop,'.');
%     f2 = figure(1);
%     zz = griddata(x,y,time_loop,xx,yy);
%     time = y;
end
z = xlsread('data.xlsx', 'sheet', 'B3:P3');
plot3(x,y,z,'.');
% imported data
zz = griddata(x,y,z,xx,yy);
f2 = figure(1); clf; hold on;
set(f2, 'renderer', 'zbuffer');
surf(xx,yy,zz);
shading flat;
%contour3(xx,yy,zz,30)
title('Thermal Plot at time')
%x axis
xlabel('x location (inches)')
%y axis
ylabel('y location (inches)')
%z axis
zlabel('z temperature (Celsius)')

如果我正确理解您的问题,那么您的问题不是关于绘图,而是关于迭代 excel 文档中的某些行。您可以通过动态生成范围来做到这一点,如下所示:

... %read x and y data
for i = 3:74
    range = ['B', num2str(i), ':P', num2str(i)];
    z = xlsread('data.xlsx', 'sheet', range);
    ... % create the plots you want for the current z values
end

最新更新