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

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 日

0 投票

%%%%%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 件のコメント

madhan ravi
madhan ravi 2018 年 10 月 19 日
what is plottingFunction?
Yuniba Yagues
Yuniba Yagues 2018 年 10 月 19 日
udata, vdata and wdata are the three double arrays (799x799 size) in the data file
madhan ravi
madhan ravi 2018 年 10 月 19 日
please upload the file , you didn't define anything as plottingFunction
Yuniba Yagues
Yuniba Yagues 2018 年 10 月 19 日
The function is supposed to take in the function style, so take in contour, or mesh, or surf as an input and output that kind of plot
Yuniba Yagues
Yuniba Yagues 2018 年 10 月 19 日
plottingFunction would be the kind of plot
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

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDiscrete Data Plots についてさらに検索

製品

リリース

R2018a

質問済み:

2018 年 10 月 19 日

コメント済み:

2018 年 10 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by