Plot velocity profiles along a slope

Hi everyone,
I'm seeking assistance with plotting velocity profiles at multiple cross-sections on a single graph and incorporating a ruler.
Any suggestions or ideas to tackle this challenge would be greatly appreciated.
Thank you!

1 Kommentar

Mathieu NOE
Mathieu NOE am 11 Mär. 2024
plotting the data in itself is not complicated
the ruler may require a bit more work , depends how sophisticted you want to have it

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Mathieu NOE
Mathieu NOE am 11 Mär. 2024
Bearbeitet: Mathieu NOE am 11 Mär. 2024

0 Stimmen

hello again
so this is a starter , would need further work to define correct range of the ruler according to your data
%% create some dummy data
x = (1:100);
ytop = 10 + 3*exp(-x/100); % top envelope curve
ybottom = 3 - 2*exp(-x/100); % bottom envelope curve
% main plot
plot(x,ytop,'k--',x,ybottom,'k-','linewidth',1.5);
ylim([0 max(ytop)+3]);
hold on
% plot "red" data at xpos1 = 25.8; % or whatever number you want
xpos1 = 25.8;
xd1 = (1:40); % local x vector (rotated 90°)
yd1 = -5*exp(-(xd1-5).^2); % local y vector (rotated 90°)
% map the xd1 range between top and bottom lines
ytop1 = interp1(x,ytop,xpos1);
ybottom1 = interp1(x,ybottom,xpos1);
xd1_mapped = linspace(ybottom1,ytop1,numel(xd1));
plot(xpos1*ones(size(xd1_mapped)),xd1_mapped,'b','linewidth',0.5); % plot the reference baseline (local y = 0)
plot(xpos1 + yd1,xd1_mapped,'r--'); % plot the data
%% Ruler
nrTicks = 9; % must be odd number !!
% Minimum and maximum values as integers for the generation of the ruler
xMin = -(nrTicks-1)/2;
xMax = -xMin;
markerXpos = xMin:xMax;
scale_factor = 1;
%
width = 2;
TickLengthMajor = width / 5;
TickLengthMinor = TickLengthMajor/2;
textOffset = 0.3;
%
% Plot the x axis
plot( [xMin xMax]*scale_factor+xpos1, [0 0]+xd1_mapped(1), 'k','linewidth',width);
% Plot end (major) ticks
for k=[1 (nrTicks+1)/2 nrTicks]
at = markerXpos( k );
bt = at*scale_factor+xpos1;
plot( [bt, bt], [0, TickLengthMajor]+xd1_mapped(1), 'k');
text( bt, - textOffset + xd1_mapped(1),...
int2str(markerXpos(k)),...
'HorizontalAlignment', 'Center');
end
% Plot in between (minor) ticks
for k=2:nrTicks-1
at = markerXpos( k );
bt = at*scale_factor+xpos1;
plot( [bt, bt], [0, TickLengthMinor]+xd1_mapped(1), 'k');
end
hold off

6 Kommentare

Mathieu NOE
Mathieu NOE am 11 Mär. 2024
I have a better rendering of the plot on my PC :
Nhat
Nhat am 13 Mär. 2024
Thank you very much.
Your code is helpful to me.
Best regards,
Mathieu NOE
Mathieu NOE am 13 Mär. 2024
my pleasure !
do you mind acepting my answer ? tx !
Nhat
Nhat am 13 Mär. 2024
Bearbeitet: Nhat am 13 Mär. 2024
Yes, You code is very good!
I thought that xMin and xMax will be changed, it depends on data. Therefore, the code at major ticks will be changed a little (int2str->num2str).
%% Plot end (major) ticks
for k=[1 (nrTicks+1)/2 nrTicks]
at = markerXpos( k );
bt = at*scale_factor+xpos1;
plot( [bt, bt], [0, TickLengthMajor]+xd1_mapped(1), 'k');
text( bt, - textOffset + xd1_mapped(1),...
num2str(markerXpos(k)),...
'HorizontalAlignment', 'Center');
end
Mathieu NOE
Mathieu NOE am 13 Mär. 2024
Yes, some adaptation to your needs may be required
Mathieu NOE
Mathieu NOE am 25 Mär. 2024
do you mind acepting my answer ? tx !

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 10 Mär. 2024

Kommentiert:

am 25 Mär. 2024

Community Treasure Hunt

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

Start Hunting!

Translated by