Azzera filtri
Azzera filtri

How to create a stickplot?

36 visualizzazioni (ultimi 30 giorni)
Emi
Emi il 6 Dic 2020
Commentato: Mathieu NOE il 2 Ott 2023
Hello,
I am trying to create a stickplot in MATLAB (velocity vector vs time), for which I'm using the stickplot.m function (attached). I have also attached a demo so you can see the result of the function. I need to change the size of the vectors, can you help me? It would be much appreciated, I'm struggling with this for over a week now.
Thank you in advance

Risposta accettata

Mathieu NOE
Mathieu NOE il 15 Dic 2020
hello
I interpreted your request as you want to change the LineWidth of the vector so it can look thicker
I added this parameter in the function - very easy
see the results (attached)
  25 Commenti
indika kathaluwa weligamage
Dear Mathieu
Stick plot is Very Beautiful and meaning full.
I tried your stick plot function for my data set.
It makes error, (Uf or variable 'myslidingavg')
Highly appreciate your help for correct this.
Kind Regard
INDIKA
% STICKDEMO This demo shows what you can do easily with STICKPLOT
% RP (WHOI) 15/Jan/91
clc
clear all;
load power_2022new.txt;
u=power_2022new(:,4);
v=power_2022new(:,5);
t=power_2022new(:,1);
% load u.mat
% load v.mat
% load t.mat
% my preference : replace NaN with zero
u(isnan(u)) = 0;
v(isnan(v)) = 0;
% display only first n samples (rest is zero)
%n = 500;
n = 366; % year data
t = t(1:n);
u = u(1:n);
v = v(1:n);
% smooting the angle
ind = find(abs(u)>eps & abs(v)>eps);
theta = zeros(size(t));
theta(ind) = atan(v(ind)./u(ind));
N_smooth = 3; % nb op points used in the averaging (the higher the smoother)
theta_smoothed = myslidingavg(theta, N_smooth);
mod = sqrt(u.^2+v.^2);
u_smoothed = mod.*cos(theta_smoothed);
v_smoothed = mod.*sin(theta_smoothed);
LineWidth1 = 2.5;
LineWidth2 = 1.5;
scale_factor = 8; % original value is 8, adapt to your onw needs (increase it if vectors overlap)
figure(1),stickplot(t,u,v,[0 length(t)],'m/s',['series 1'],LineWidth1,LineWidth2,scale_factor);grid
title('No angle smoothing');
% figure(2),plot(t,theta,'b',t,theta_smoothed,'r')
% figure(3),stickplot(t,u_smoothed,v_smoothed,[0 length(t)],'m/s',['series 1'],LineWidth1,LineWidth2,scale_factor);grid
% title('With angle smoothing');
% % figure,plot(t,u,'-+b',t,v,'-+r');grid
% %
% % figure, feather(u,v)
figure(2),
scale = 1;
% quiver(u,v)
quiver(t,0,u,v,scale)
axis equal
% QUIVER(U,V,S) or QUIVER(X,Y,U,V,S) automatically scales the
% arrows to fit within the grid and then stretches them by S. Use
% S=0 to plot the arrows without the automatic scaling.
1 58.5 4.39
2 62.81 5.99
3 69.56 5.83
4 67 4.88
5 110.44 2.09
6 78.25 3.9
7 69.69 4.26
8 40.31 3.02
9 58.81 3.69
10 118.62 2.11
11 125.12 2.11
12 163.56 2.31
13 197.88 2.56
14 126.88 1.77
15 75.06 1.72
16 55.69 4.48
17 62.5 5.11
18 61.44 4.14
19 44.81 4.49
20 130.12 2.73
21 255.25 1.59
22 216 1.54
23 141.62 1.45
24 120.94 1.8
25 93.25 2.52
26 60.5 2.71
27 49.88 3.48
28 76.25 3.53
29 108.25 3.03
30 90.44 3.49
Mathieu NOE
Mathieu NOE il 2 Ott 2023
attached is the function myslindingavg
nota that now matlab has also plenty of option to smooth data like smoothdata

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by