How to create a bar graph from imported data where each bar represents a tested weight for a model and this weight has associated force and z-CoM position data

3 visualizaciones (últimos 30 días)
I am trying to plot a bar graph based on data from a Robotic arm gripper model in Matlab with force on the y axis and categorical weight on x axis (1, 2, 5, 10, 20, 30, 50kg). Each weight has an table array where column one is the force applied (which varies for each weight) and column two is the associated z-CoM for that force.
Weight is on the x axis, there will be one bar per weight that has been tested. Force applied is on the y-axis and there are different force ranges for each weight. Additionally, the bars for each weight are plotted so that if the z-CoM position is above a threshold value of 0.91m for the corresponding force in the table then the bar will be green and if it is below this value then the bar will be red.
Here is my code so far, it produces a bar graph but the values on the x-axis are 1-6 whereas they should be the weight values and the whole bar appears green which it shouldn't as there is a lot of z-CoM which do not reach my threshold value and therefore some part of the bar should appear red.
%% Weight Range Plot - Two Jaw Parallel Gripper
% data for weight, force, and z-CoM values
weights = {'1', '2', '5', '10', '20', '30'};
force_data = {(TwoJPG1(:,1)), (TwoJPG2(:,1)), (TwoJPG5(:,1)), (TwoJPG10(:,1)), (TwoJPG20(:,1)), (TwoJPG30(:,1))};
zcom_data = {(TwoJPG1(:,2)), (TwoJPG2(:,2)), (TwoJPG5(:,2)), (TwoJPG10(:,2)), (TwoJPG20(:,2)), (TwoJPG30(:,2)),};
% Determine force ranges for each weight
force_ranges = {(max(TwoJPG1(:,1))-min(TwoJPG1(:,1))), (max(TwoJPG2(:,1))-min(TwoJPG2(:,1))), ...
(max(TwoJPG5(:,1))-min(TwoJPG5(:,1))), (max(TwoJPG10(:,1))-min(TwoJPG10(:,1))), (max(TwoJPG20(:,1))-min(TwoJPG20(:,1))), (max(TwoJPG30(:,1))-min(TwoJPG30(:,1)))};
% Set threshold value for z-CoM
zcom_threshold = 0.91;
% Create bar graph
figure;
hold on;
for i = 1:length(force_ranges)
weight = weights{i};
force_vals = force_data{i};
zcom_vals = zcom_data{i};
for j = 1:length(force_vals)
force = force_vals(j);
zcom = zcom_vals(j);
if zcom > zcom_threshold
bar(i, force, 'FaceColor', 'g');
else
bar(i, force, 'FaceColor', 'r');
end
end
end
% Add axis labels and legend
xlabel('Weight');
ylabel('Force');
legend('Above Threshold', 'Below Threshold');
Here is an example of my data for one of the data sets; (column one is force applied and column two is z-CoM data)
0 0.148753795744176
5 0.150000000000000
10 1.79734909261850
15 0.150000000000000
20 0.150000000000000
25 0.448829954360282
30 0.902732421109797
35 0.939782030820428
40 0.945294812544202
45 0.945304818218762
50 0.945304912457884
55 0.945305006700347
60 0.945305100945238
65 0.945305195191971
70 0.945305289440265
75 0.945305383689671
80 0.945305477940264
85 0.945305572191835
90 0.945305666444596
95 0.945305760698973
100 0.945305854954752
105 0.945305949212668
110 0.945306043472667
115 0.945306137735048
120 0.945306232000405
If anyone can help I would really appreciate it.
  5 comentarios
Cris LaPierre
Cris LaPierre el 5 de Abr. de 2023
What value do you intend to use to create your bar plot? The max force in the table (last row)? the force_range value? The average force?
For the sample data you shared above, the data is for one arm at one specific weight, but contains 25 rows of data. Currently, your code loops thorugh each row, creating a new bar plot for each row, all at the same X location. That seems incorrect.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre MATLAB 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!

Translated by