Generate bar graph in a for loop

4 次查看(过去 30 天)
JC
JC 2020-7-8
评论: dpb 2020-7-10
So I have data in a 32*1 cell and I would like to plot them on bar graphs. The complicated part is I dont need 32 bar graphs, I would like to group these values in groups of 4. So I would have a total of 8 bar graphs. please help
clc
clear
warning('off','all')
d = dir('*.csv');
dm = dir('*.mat');
nm = numel(dm);
n = numel(d);
firewall = cell(32, 1);
firewall_array = cell(32, 1);
Y_Firewall_avg_4_24 = cell(32, 1);
UDT = cell(32, 1);
UDT_array = cell(32, 1);
X_UDT = cell(32, 1);
Y_UDT = cell(32, 1);
Y_UDT_avg_4_24 = cell(32, 1);
Wan = cell(32, 1);
Wan_array = cell(32, 1);
X_Wan = cell(32, 1);
Y_Wan = cell(32, 1);
Y_Wan_avg_4_24 = cell(32, 1);
X_Firewall = cell(32, 1);
Y_Firewall = cell(32, 1);
Digitized_graphs = cell(32,1);
XDS = cell(32,1);
YDS = cell(32,1);
X_DS = cell(32,1);
Y_DS = cell(32,1);
Y_DS_avg_4_24 = cell(32,1);
y_Bar_4_24 = cell(32,1);
% X = cell(32,1);
% b = cell(32,1);
for k = 1 : 32
firewall{k} = readtable(sprintf('Scenario%d.csv', k));
UDT{k} = readtable(sprintf('udt_scenario_%d.csv',k));
Wan{k} = readtable(sprintf('WAN_Scenario%d.csv',k));
firewall_array{k} = table2array(firewall{k}(:,[3,5]));
UDT_array{k} = table2array(UDT{k}(:,[3,4]));
Wan_array{k} = table2array(Wan{k});
Y_Firewall{k} = [firewall_array{k}(:,1)];
Y_UDT{k} = [UDT_array{k}(:,2)];
Y_Wan{k} = [Wan_array{k}(:,2)];
Y_Firewall_avg_4_24{k} = mean(Y_Firewall{k});
Y_Wan_avg_4_24{k} = mean(Y_Wan{k});
Y_DS_avg_4_24{k} = mean(Y_DS{k});
Y_UDT_avg_4_24{k} = mean(Y_UDT{k});
bar([Y_Firewall_avg_4_24{k} Y_Wan_avg_4_24{k} Y_DS_avg_4_24{k} Y_UDT_avg_4_24{k} ; Y_Firewall_avg_4_24{k+1} Y_Wan_avg_4_24{k+1} Y_DS_avg_4_24{k+1} Y_UDT_avg_4_24{k+1} ])
end
  16 个评论
dpb
dpb 2020-7-9
编辑:dpb 2020-7-9
Attach the .csv text files w/ the paperclip -- nobody can do anything with images.
I looked at your original code some more -- there are varying numbers of columns in the different files -- when read w/ readtable you'll get variable names -- is there some list of "who's who in the zoo" as to which should be selected from which file for the purpose of the graphs?
Need to write down the specific ground rules for what is wanted to be done so can write code to match. That's what you need to be able to define which columns count for what.
Ideal would be to zip up the lot so somebody if gets chance can actually solve your problem...
I can see enough to outline code as said but can't test much although the answer to the above Q? regarding the rules on how to know which columns to use for each is important piece of the puzzle.
Remember, we only know what you tell us; we can't know what you know about the problem so how to know what it makes sense to compare is all greek to us...
dpb
dpb 2020-7-10
Is the above image an output table/spreadsheet of computed results or the input files? I'm guessing the former as that doesn't really match up with the initial code...but it doesn't seem to make a lot of sense in comparison either with the multiple columns.
I'd be glad to help further if could just figure out what the first-source data really are we're starting from...

请先登录,再进行评论。

回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by