How to create subplots from a data set by using a function
13 次查看(过去 30 天)
显示 更早的评论
I am trying to make a function that will take a plotting function such as contourf or mesh, as well as nx (number of points) and dx (horizontal resolution) and will give three plots of the three arrays that are in the file. It is giving me an error saying that the plottingFunction doesn't have enough input arguments. Any ideas on what I'm doing wrong? The data file contains three double arrays which are to be plotted separately, udata, vdata and wdata
Thanks
function fig = plotVelocityComponents(plottingFunction, dx, nx)
load('dx0025_203m.mat')
x = linspace(0,nx*dx,nx);
y = linspace(0,nx*dx,nx);
%
[X, Y] = meshgrid(x,y);
Zu = udata(1:nx,1:nx)
Zv = vdata(1:nx,1:nx)
Zw = wdata(1:nx,1:nx)
%
subplot(1,3,1)
plottingFunction(X, Y, Zu)
title('u-velocity')
xlabel('x(km)')
ylabel('y(km)')
colorbar
%
subplot(1,3,2)
plottingFunction(X, Y, Zv)
title('v-velocity')
xlabel('x(km)')
ylabel('y(km)')
colorbar
%
subplot(1,3,3);
plottingFunction(X, Y, Zw);
title('w-velocity');
xlabel('x(km)');
ylabel('y(km)');
colorbar;
fig = subplot; % end
0 个评论
回答(1 个)
madhan ravi
2018-10-19
编辑:madhan ravi
2018-10-19
%%%%%script file
datas = load('dx0025_203m.mat')
dx = datas(:,1)
nx = datas(:,2) %assumption cause you didn't upload mat file
fig1 = plotVelocityComponents(plottingFunction, dx, nx) %calling of the function % changed fig as fig1 because Matlab as an inbuilt function name as fig
%%%%%%%%%function file
function fig1 = plotVelocityComponents(plottingFunction, dx, nx)
x = linspace(0,nx*dx,nx);
y = linspace(0,nx*dx,nx);
%
[X, Y] = meshgrid(x,y);
Zu = udata(1:nx,1:nx) %???--|
Zv = vdata(1:nx,1:nx) %???--|-> what are these datas?
Zw = wdata(1:nx,1:nx) %???--|
%
subplot(1,3,1)
plottingFunction(X, Y, Zu)
title('u-velocity')
xlabel('x(km)')
ylabel('y(km)')
colorbar
%
subplot(1,3,2)
plottingFunction(X, Y, Zv) % plottingFunction ? what does it mean ? no inbuilt function as such
title('v-velocity')
xlabel('x(km)')
ylabel('y(km)')
colorbar
%
fig1 = subplot;
%
end
7 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Discrete Data Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!