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

100 visualizzazioni (ultimi 30 giorni)
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')

Risposta accettata

Cris LaPierre
Cris LaPierre il 26 Ott 2021
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 Commenti
Cris LaPierre
Cris LaPierre il 26 Ott 2021
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 il 27 Ott 2021
Modificato: chiefjia il 27 Ott 2021
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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Discrete Data 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