Struct contents reference from a non-struct array object. error in a code
4 次查看(过去 30 天)
显示 更早的评论
%%clmap.m
clear all
close
load('config.mat')
%number of classes
clmax
%number of trees
mmax
%number of population per class
nmax
%max depth
depthmax
markers=['x','o','.','s','*','d','^','v','>','<'];
colors=[ hex2dec('1f')/255 hex2dec('77')/255 hex2dec('b4')/255;
hex2dec('ff')/255 hex2dec('7f')/255 hex2dec('0e')/255;
hex2dec('2c')/255 hex2dec('a0')/255 hex2dec('2c')/255;
hex2dec('d6')/255 hex2dec('27')/255 hex2dec('28')/255;
hex2dec('94')/255 hex2dec('67')/255 hex2dec('bd')/255;
hex2dec('8c')/255 hex2dec('56')/255 hex2dec('4b')/255;
hex2dec('e3')/255 hex2dec('77')/255 hex2dec('c2')/255;
hex2dec('7f')/255 hex2dec('7f')/255 hex2dec('7f')/255;
hex2dec('bc')/255 hex2dec('bd')/255 hex2dec('22')/255;
hex2dec('17')/255 hex2dec('be')/255 hex2dec('cf')/255];
PQ=zeros(mmax,clmax);
xmax=40;
ymax=40;
%img=ones(ymax,xmax);
img=ones(ymax,xmax,3);
trees=[];
for m=1:mmax
load(strcat('tree',sprintf('%02d.mat',m)));
trees= [trees sroot];
end
for i=1:xmax
for j=1:ymax
theta=[i/xmax,j/ymax];
for m=1:mmax
parent=trees(m);
%display(strcat('tree',sprintf('%02d ',m)));
while 1
if theta(parent.theta)< parent.tau
next_parent=parent.BL;
%display(sprintf('L '));
else
next_parent=parent.BR;
%display(sprintf('R '));
end
if isempty(next_parent)
PQ(m,:)=parent.PQ;
break;
else
parent=next_parent;
end
end
end
Pout=sum(PQ,1)/mmax;
%[v index]=max(parent.PQ);
%img(j,i)=index;
img(j,i,:)=Pout*colors(1:clmax,:);
end
end
%imshow(img,colors,'Border','tight');
imshow(img,'Border','tight');
hold on
load('data.mat');
for i=1:size(data,1)
plot(data(i,1)*xmax,data(i,2)*ymax, strcat(markers(data(i,3)),'k'));
end
axis xy
..
..
*error is*
In show (line 26)
Struct contents reference from a non-struct array object.
Error in show (line 36)
if theta(parent.theta) < parent.tau
0 个评论
采纳的回答
Guillaume
2017-9-19
编辑:Guillaume
2017-9-19
Your code is expecting that the sroot variable, which presumably gets popped into existence by your load(strcat('tree',sprintf('%02d.mat',m)));, to be a structure.
As the error message tells you, it is not.
The fix is to either change your code to reflect whatever that sroot is, or change the content of the mat file so that sroot is a structure.
PS: I bet that was a lot of fun copy-pasting these repeated hex2dec()/255. A much easier way to obtain the same thing:
colorshex = ['1f77b4'
'ff7f0e'
'2ca02c'
'd62728'
'9467bd'
'8c564b'
'e377c2'
'7f7f7f'
'bcbd22'
'17becf'];
colors = floor(mod(hex2dec(colorshex) ./ [2^16 2^8 1], 256)) / 255;
1 个评论
Stephen23
2023-4-19
Another approach:
H = ['1f77b4';'ff7f0e';'2ca02c';'d62728';'9467bd';'8c564b';'e377c2';'7f7f7f';'bcbd22';'17becf'];
M = sscanf(H.','%2x',[3,Inf]).'./255
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!