Unrecognized method, property, or field 'value' for class 'matlab.gr​aphics.cha​rt.primiti​ve.Bar'.

104 次查看(过去 30 天)
I am getting the following error for the code below: Unrecognized method, property, or field 'orig_short_position' for class 'matlab.graphics.chart.primitive.Bar'. I don't know how to fix this, does anyone have any suggestion? You can find origBar_input attached
% Displaying the 20 position dates with the highest frequency of appearance
origBar_input = orig_short_positionFrequency(1:20, [1 3]);
bar(origBar_input.orig_short_position, origBar_input.percentage);
origBar_input.Parent.XTick = 1:size(origBar_input, 1);
origBar_input.Parent.XTickLabel = origBar_input.orig_short_position;
origBar_input.Parent.XTickLabelRotation = 35; % rotate labels
origBar_input.Parent.XAxis.FontSize = 7; % reduce font size fo better visualization
ylabel('%')
title('Distribution of orig short position Frequency')

采纳的回答

Cris LaPierre
Cris LaPierre 2021-10-26
It looks like the code shared here is not the same code that created that error. Can you check that you copied the correct code? Also, please copy the entire error message (all the red text).
What version of MATLAB are you using?
I can recreate your error message if I create a graphics object to the bar plot using the same variable name as your table. If that is what you did, giver your bar object a different name.
load origBar_input.mat
%vvvvvvvvvvvv -----> Use a unique variable name
origBar_input = bar(origBar_input.orig_short_position, origBar_input.percentage);
origBar_input.Parent.XTick = 1:size(origBar_input, 1);
%vvvvvvvvvvvv <----------------> vvvvvvvvvvvvv Using same name
origBar_input.Parent.XTickLabel = origBar_input.orig_short_position;
Unrecognized method, property, or field 'orig_short_position' for class 'matlab.graphics.chart.primitive.Bar'.
  2 个评论
Cris LaPierre
Cris LaPierre 2021-10-26
load origBar_input.mat
b = bar(origBar_input.orig_short_position, origBar_input.percentage);
b.Parent.XTick = 1:size(origBar_input, 1);
b.Parent.XTickLabel = origBar_input.orig_short_position;
b.Parent.XTickLabelRotation = 35; % rotate labels
b.Parent.XAxis.FontSize = 7; % reduce font size fo better visualization
ylabel('%')
title('Distribution of orig short position Frequency')
chiefjia
chiefjia 2021-10-27
编辑:chiefjia 2021-10-27
Dear Cris,
yes, that's exactly the error that I'm getting, so the way to fix it is just changing the name of the bar plot to something different to origBar_input? Also, I don't understand way the bars in the plot are so narrow, since when applying exactly the same code to other values of the x label, the bar plots are thicker and the values of each one of the bins in the x axis show. You can find the example of what I mean in the figure attached.
PD: Solved it and found out it was because I didn't convert
origBar_input.orig_short_position
into a categorical
Thank you in advance.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Discrete Data Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by