Create Bar Charts with different number of groups for each iteration.
2 views (last 30 days)
Show older comments
Hi,
I would like to create for each iteration a bar chart. However, the number of groups changes by each iteration and I do not want to change the Var manually for each iteration. Here is my code:
for f=1:nBFonds
figure(f)
pInd=transpose(peersInd==f);
Var=[TotRetB(1,f);TotRetPeers(:,pInd)]; %--> TotRetPeers(:,pInd) is a 1x26 vector. In the second iteration the values in the columns 3-5
% will be needed. So, in total (with the value in TotRetB(1,f) the bar char will have a group of 6. For the next iteration however (depending
% in the indicator variable pInd the columns 6-10 will create another group with TotaRet(1,3). TotRetB is a 1x5 vector. nBFonds=5
bar(Var);
end
thank you for your help
0 Comments
Answers (1)
darova
on 27 Mar 2020
Try NaN
for f=1:nBFonds
figure(f)
Var = nan(1,26);
pInd=transpose(peersInd==f);
Var1 = [TotRetB(1,f);TotRetPeers(:,pInd)]; %--> TotRetPeers(:,pInd) is a 1x26 vector. In the second iteration the values in the columns 3-5
ii = 1:length(Var1);
Var(ii) = Var1;
% will be needed. So, in total (with the value in TotRetB(1,f) the bar char will have a group of 6. For the next iteration however (depending
% in the indicator variable pInd the columns 6-10 will create another group with TotaRet(1,3). TotRetB is a 1x5 vector. nBFonds=5
bar(Var);
end
0 Comments
See Also
Categories
Find more on Bar Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!