How to create subplots from a data set by using a function

조회 수: 13 (최근 30일)
Yuniba Yagues
Yuniba Yagues 2018년 10월 19일
댓글: madhan ravi 2018년 10월 19일
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

답변 (1개)

madhan ravi
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
Yuniba Yagues
Yuniba Yagues 2018년 10월 19일
File is too big to upload, plottingFunction is just an arbitrary input
madhan ravi
madhan ravi 2018년 10월 19일
ok I understood give me few minutes

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by