How do I changethe label in a compass graph

7 ビュー (過去 30 日間)
olivier task
olivier task 2021 年 1 月 16 日
コメント済み: dpb 2021 年 1 月 17 日
Hello
Here is my code , I find it in the documentation.
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);

回答 (1 件)

dpb
dpb 2021 年 1 月 16 日
編集済み: dpb 2021 年 1 月 16 日
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 件のコメント
olivier task
olivier task 2021 年 1 月 17 日
Thank you for your investment. I am finally using polarplot. I can't draw the arrow, but the plot is enough.
https://thingspeak.com/apps/matlab_visualizations/319108?size=iframe
Best regards. Olivier
dpb
dpb 2021 年 1 月 17 日
Don't blame you... :)
You could probably add annotations for the arrowheads to polarplot although I've not explored that option.

サインインしてコメントする。

コミュニティ

その他の回答  ThingSpeak コミュニティ

カテゴリ

Help Center および File ExchangePolar Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by