Struct contents reference from a non-struct array object. error in a code

1 visualización (últimos 30 días)
%%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

Respuesta aceptada

Guillaume
Guillaume el 19 de Sept. de 2017
Editada: Guillaume el 19 de Sept. de 2017
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 comentario
Stephen23
Stephen23 el 19 de Abr. de 2023
Another approach:
H = ['1f77b4';'ff7f0e';'2ca02c';'d62728';'9467bd';'8c564b';'e377c2';'7f7f7f';'bcbd22';'17becf'];
M = sscanf(H.','%2x',[3,Inf]).'./255
M = 10×3
0.1216 0.4667 0.7059 1.0000 0.4980 0.0549 0.1725 0.6275 0.1725 0.8392 0.1529 0.1569 0.5804 0.4039 0.7412 0.5490 0.3373 0.2941 0.8902 0.4667 0.7608 0.4980 0.4980 0.4980 0.7373 0.7412 0.1333 0.0902 0.7451 0.8118

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by