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

3 visualizaciones (últimos 30 días)
BdS
BdS el 27 de Mzo. de 2020
Respondida: darova el 27 de Mzo. de 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

Respuestas (1)

darova
darova el 27 de Mzo. de 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

Categorías

Más información sobre Bar Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by