How do I changethe label in a compass graph
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello
Here is my code , I find it in the documentation.
I would change the label like here : https://fr.mathworks.com/help/matlab/creating_plots/compass-labels-on-polar-axes.html
but I always get a mathlab error and I don't understand why.
Thank's , Olivier
% Channel ID to read data from
readChannelID = 926212;
WindDirFieldID = 4;
WindSpeedFieldID = 3;
readAPIKey = 'XXXXXXXXXXXXXXX';
windDir = thingSpeakRead(readChannelID,'Fields',WindDirFieldID,'NumPoints',10,...
'ReadKey',readAPIKey);
windSpeed = thingSpeakRead(readChannelID,'Fields',WindSpeedFieldID,'NumPoints',10,...
'ReadKey',readAPIKey);
rad = windDir*2*pi/360;
rad = (rad+pi/2);
u = -cos(rad) .* windSpeed;
v = sin(rad) .* windSpeed;
title('anemo');
%pax = gca;
angles = 0:45:360;
pax.ThetaTick = angles;
labels = {'E','NE','N','NW','W','SW','S','SE'};
pax.ThetaTickLabel = labels;
compass(u,v);
0 comentarios
Respuestas (1)
dpb
el 16 de En. de 2021
Editada: dpb
el 16 de En. de 2021
Well, the above code commented out
pax=gca;
so the handle to the axes is either undefined or refers to a probably no longer existing object if the variable exists from a previous run. Or, if there is no variable pax the first time the code is run it will be created by the dot notation as a struct:
windSpeed=randi(30,size(windDir));
windDir=deg2rad(randi(360,10,1)-1);
u = -cos(rad) .* windSpeed;
v = sin(rad) .* windSpeed;
title('anemo');
%pax = gca;
angles = 0:45:360;
pax.ThetaTick = angles;
labels = {'E','NE','N','NW','W','SW','S','SE'};
pax.ThetaTickLabel = labels;
compass(u,v);
executed when there was no variable pax in the workspace resulted in
>> pax
pax =
struct with fields:
ThetaTick: [0 45 90 135 180 225 270 315 360]
ThetaTickLabel: {'E' 'NE' 'N' 'NW' 'W' 'SW' 'S' 'SE'}
>>
But, the bigger problem is that the example is for polarplot which creates a PolarAxes object and you drew a compass plot which uses a regular Cartesian axes object which does not have the properties 'ThetaTick', 'ThetaTickLabel' but computes and draws a polar coordinate system axis/lines in cartesian coordinates.
A quick perusal didn't uncover just how those are done or where those properties might be buried but they're not easily accessible it seems.
Alternatively, you might try to draw a polarplot() object to label and then add the compass plot on top...but I'm not sure how you'd turn off the labels...and I don't have time to delve more deeply at the moment, sorry.
This looks like a Q? to official support, mayhaps with a request for enhancement to get compass() to also use the polar axes object.
4 comentarios
dpb
el 17 de En. de 2021
Don't blame you... :)
You could probably add annotations for the arrowheads to polarplot although I've not explored that option.
Comunidades de usuarios
Más respuestas en ThingSpeak Community
Ver también
Categorías
Más información sobre Polar Plots en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!