Too many dimensions error msg in figure

조회 수: 1 (최근 30일)
Karl
Karl 2013년 5월 27일
I get the message "Error using plot Data may not have more than 2 dimensions" when running the follwoing commands:
Alder = {'<20', '2029','3039','4049','5059','6069','>70', 'all'};
Vars = {AlG, AlR, AlI, AlDI, AlBV};
Vars2 = {'AlG', 'AlR', 'AlI', 'AlDI', 'AlBV'};
Aar = {'2011', '2012', '2013_1', '2014_1', '2014_s2', '2014_s5'};
n = length(Vars);
nAar = length(Aar);
nAl = length(Alder);
numberOfColors = nAl;
myColorMap = lines(numberOfColors);
for iVars = 1:n;
aVars = Vars{iVars};
figure,title(Vars2{iVars});
hold on
for iAl = 1:nAl
plot(aVars(11,iAl,:), 'color', myColorMap((iAl), :));
set(gca, 'XTickLabel',Aar)
legend((Alder),'location','NE','FontSize',10);
end
hold off
end
plot(aVars(11,1,:), 'color', myColorMap((iAl), :));
All matrices inn "Vars" is 11x8x6 matrices. I don't understand why the above commands fails, since almost the same commands work in this case below. The only difference is that in the above script I have "Alder" on the x-axis and in the below script I have "Aar" on the x-axis.
Alder = {'<20', '2029','3039','4049','5059','6069','>70', 'all'};
Vars = {gjG, gjR, gjI, gjDI, gjBV, GtoDI, GtoBV, RtoDIplusR, ItoG, RtoG, GtoI};
Vars2 = {'gjG', 'gjR', 'gjI', 'gjDI', 'gjBV', 'GtoDI', 'GtoBV', 'RtoDIplusR', 'ItoG', 'RtoG', 'GtoI'};
Aar = {'2011', '2012', '2013_1', '2014_1', '2014_s2', '2014_s5'};
n = length(Vars);
nAar = length(Aar);
numberOfColors = 6;
myColorMap = lines(numberOfColors);
for iVars = 1:n;
aVars = Vars{iVars};
figure,title(Vars2{iVars});
hold on
for iAar = 1:nAar
plot(aVars(11,:,iAar), 'color', myColorMap((iAar), :));
set(gca, 'XTickLabel',Alder)
legend((Aar),'location','NE','FontSize',10);
end
hold off
end

채택된 답변

Walter Roberson
Walter Roberson 2013년 5월 27일
plot( squeeze(aVars(11,iAl,:)), 'color', myColorMap((iAl), :));
In the first one you had a 3D matrix accessed at (specific value, specific value, :) . In MATLAB the result of that would be 1 x 1 x N, a 3D result. MATLAB cannot plot 3D vectors.
In the second one you had a 3D matrix accessed at (specific value, :, specific value). In MATLAB the result of that would be 1 x N x 1 and then the trailing 1's get dropped, leaving 1 x N which is a 2D result; MATLAB is able to plot with 2D vectors.
The squeeze() I added above transforms the 3D vector into a 2D vector.
  댓글 수: 1
Karl
Karl 2013년 5월 29일
It worked! Thank you so much!

댓글을 달려면 로그인하십시오.

추가 답변 (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