How to create subplots from a data set by using a function
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
madhan ravi
am 19 Okt. 2018
Bearbeitet: madhan ravi
am 19 Okt. 2018
%%%%%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 Kommentare
Siehe auch
Kategorien
Mehr zu Discrete Data Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!