plot pressure as vectors on a curve

3 views (last 30 days)
How can i plot this? I have coordinates for the cross section as well as the pressure in each point. Tried to use the quiver function, but then the vectors is not normal on the cross section.

Accepted Answer

Thea Jahren Herud
Thea Jahren Herud on 20 Apr 2020
The coordinates and pressure are attached in the xlsx file

More Answers (1)

BALAJI KARTHEEK
BALAJI KARTHEEK on 20 Apr 2020
here, I am attaching two files and the graph of the output for the excel data given by u. The first is regarding the function file and the second file is for the code. I hope u got what got u want.. If u have any doubts please feel to ask me...contact me on watsapp+91 7893397808.. i am doing all this stuff because i dont know what to do in quarentine hahahah......
function quiverC2D(x,y,u,v,varargin)
%quiverC2D creates a 2D quiver plot and adds a color coding. The color coding is
%given by the absolut values of the component vectors. Large values result in colors
%from the upper end of the used colormap. Plotting parameters have to be changed within
%the function in this version. Values equal to NaN or inf are set to zero.
%In case of complex arrays the absolute value is used.
%
% INPUT:
% x - array, x components of initial points
% y - array, y components of initial points
% u - array, x components of arrows
% v - array, y components of arrows
% scale - number, if > 0, automatic scaling is used to avoid overlap
% of adjacent arrows. If scale = 0, the scaling is disabled.
% maxNumArrows - a positive integer (non-integer should work as well)
% number limiting the maximum number of plotted arrows. Since vectors
% of length zero aren't plotted and the matrices are sampled
% uniformly, it's possible that fewer arrows will be visible in the
% end. If maxNumArrows is not given its value is set to inf.
%
% OUTPUT:
% none
%
% WARNING!: This function might not create arrows with the same length as
% would be obtained using quiver(x, y, u, v). I do not know whether the
% scaling method is the same is in quiver.
%
% --------------------------------------------------------------------------------------
%
% EXAMPLE:
% load wind
% quiverC2D(x(:,:,1),y(:,:,1),u(:,:,1),v(:,:,1),1);
% set(gca, 'Color', 'black');
% axis tight
% axis equal
%
% --------------------------------------------------------------------------------------
%
% See also: QUIVER, LINESPEC, COLORMAP.
%
%
%% parse arguments
p = inputParser;
addRequired(p, 'x', @isnumeric);
addRequired(p, 'y', @isnumeric);
addRequired(p, 'u', @isnumeric);
addRequired(p, 'v', @isnumeric);
addOptional(p, 'scale', 1, @isscalar);
addOptional(p, 'MaxNumArrows', inf, @isscalar);
addParameter(p, 'Normalize', false);
addParameter(p, 'LineWidth', 0.5, @isscalar);
addParameter(p, 'MaxHeadSize', 1, @isscalar);
addParameter(p, 'Parent', gca(), @isgraphics);
parse(p, x, y, u, v, varargin{:});
scale = p.Results.scale;
maxnumarrows = p.Results.MaxNumArrows;
normalize = p.Results.Normalize;
lw = p.Results.LineWidth;
hs = p.Results.MaxHeadSize;
ax = p.Results.Parent;
assert(scale >= 0);
if ~isequal(size(x),size(y),size(u),size(v))
error('X,Y,Z,U,V,W have to be arrays of the same size.');
end
%% initialization
if numel(u) > maxnumarrows
if isvector(u)
N = ceil(numel(u)/maxnumarrows);
else
N = ceil(nthroot(numel(u)/maxnumarrows, ndims(u)));
end
if isvector(x)
idx = {1:N:length(x)};
else
idx = arrayfun(@(x) 1:N:x, size(x), 'UniformOutput', false);
end
x = x(idx{:});
y = y(idx{:});
u = u(idx{:});
v = v(idx{:});
end
%% colormap definition
C = colormap(ax);
ncolors = size(C, 1);
I = sqrt(u.^2 + v.^2);
if verLessThan('matlab','9.5')
Imax = max(I(:), [], 'omitnan');
else
Imax = max(I, [], 'all', 'omitnan');
end
% assume that the colormap matrix contains the colors in its rows
Ic = round(I/Imax*ncolors);
Ic(Ic == 0) = 1;
if normalize
u = u./I;
v = v./I;
else
% scale not to overlap
if scale > 0
[~,dxi] = uniquetol(x);
dx = diff(x(sort(dxi)));
[~,dyi] = uniquetol(y);
dy = diff(y(sort(dyi)));
% avg difference
dr_mean = mean(abs([dx; dy]));
lenscale = scale*dr_mean/Imax;
else
lenscale = 1;
end
end
u = u*lenscale;
v = v*lenscale;
%% plotting
ishold_flag = ishold(ax);
hold(ax, 'on');
if numel(u) > ncolors
% let's take an intelligent approach: group all values which belong to
% the same color value
for k = 1:ncolors
mask = (Ic == k);
quiver(ax, x(mask), y(mask), u(mask), v(mask), 0, ...
'Color', C(k, :), 'LineWidth', lw, 'MaxHeadSize', hs);
end
else
% if there are so few values, it will be more efficient to plot each
% arrow individually
% linear indexing!
for k = 1:numel(u)
quiver(ax, x(k), y(k), u(k), v(k), 0, 'Color', C(Ic(k),:), ...
'LineWidth', lw, 'MaxHeadSize', hs);
end
end
if ~ishold_flag
hold(ax, 'off');
end
end
clc
clear all
x=[37.14
23.015
8.89
-5.235
-19.36
-33.109975
-46.85995
-60.609925
-74.3599
-84.57419971
-94.78849942
-105.0029991
-115.2170988
-125.4313986
-135.6456983
-145.859998
-151.8348737
-158.43218
-165.0294863
-171.6267925
-170.9920878
-162.9372643
-154.8824408
-146.8276173
-138.7727939
-130.7179704
-122.6631469
-114.6083234
-106.5535
-98.49867649
-90.44385302
-82.38902954
-75.86
-74.562
-53.264
-41.966
-30.668
-19.37
-5.245
8.88
23.005
37.13
40.64
40.64
40.64
40.64
40.64
40.64
];
y=[40
40
40
40
40
40
40
40
40
40
40
40
40
40
40
40
37.52512627
30.92782
24.33051373
17.73320746
12.90381057
8.25335602
3.60290152
-1.04755298
-5.69800748
-10.34846198
-14.99891648
-19.64937098
-24.29982548
-28.95027998
-33.60073448
-38.25118898
-40
-40
-40
-40
-40
-40
-40
-40
-40
-40
-36.5
-21.9
-7.3
7.3
21.9
36.5
];
z=[23
43
23
45
33
32
33
53
23
45
34
54
33
54
34
23
24
22
24
43
43
23
12
23
10
11
22
21
24
12
23
54
10
11
22
21
24
12
23
54
41.28571429
45.64285714
50
54.35714286
58.71428571
63.07142857
67.42857143
71.78571429
];
a=(x./sqrt(x.*x+y.*y));
b=(y./sqrt(x.*x+y.*y));
a1=z.*a;
b1=z.*b;
plot(x,y)
hold on
quiverC2D(x,y,a1,b1)

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!