Create Bar Charts with different number of groups for each iteration.

3 Ansichten (letzte 30 Tage)
BdS
BdS am 27 Mär. 2020
Beantwortet: darova am 27 Mär. 2020
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

Antworten (1)

darova
darova am 27 Mär. 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

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by