필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
BdS
BdS 2020년 3월 27일
답변: darova 2020년 3월 27일
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

답변 (1개)

darova
darova 2020년 3월 27일
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

카테고리

Help CenterFile Exchange에서 Bar Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by