Index exceeds the number of array elements (63). Error in ANA (line 23) figure;plo​t(Xdetecti​ons(index_​maxplot));

1 view (last 30 days)
[cols, rows] = size(fHist); %create an array [number of columns x number of rows]
for index = 1:rows %do the loop for however many rows we have
if isempty(fHist(index).pointCloud)
else
Xdetections = fHist(index).pointCloud(1,:);
Ydetections = fHist(index).pointCloud(2,:);
Zdetections = fHist(index).pointCloud(3,:);
Adetections = fHist(index).pointCloud(5,:);
% mean(Adetections)
index_maxall=find(Adetections==max(Adetections));
index_max(index,1)=index_maxall(1);
end
%Position_accuracy_matrix = (FrameNumber, IndexOfMax)
end
%disp('Loop done')
%Adetections = median(index_maxall);
index_maxplot=index_max(find(index_max>0));
figure;plot(Xdetections(index_maxplot));
figure;plot(Ydetections(index_maxplot));
figure;plot(Zdetections(index_maxplot));
figure;plot(Adetections(index_maxplot));
%--- calculate threshold for point selection to follow
frame_max = max(Adetections(index_maxplot));
frame_ave = mean(Adetections(index_maxplot));
threshold1 = (frame_max + frame_ave)/2;
%----
max_2assess = find(Adetections(index_maxplot)>threshold1);
%--- the spreads for XYZ and A
xspread1 = double(unique(Xdetections(index_maxplot(max_2assess))));
x_min = min(xspread1);
x_tol = max(xspread1)-min(xspread1);
yspread1 = double(unique(Ydetections(index_maxplot(max_2assess))));
y_min = min(yspread1);
y_tol = max(yspread1)-min(yspread1);
zspread1 = double(unique(Zdetections(index_maxplot(max_2assess))));
z_min = min(zspread1);
z_tol = max(zspread1)-min(zspread1);
Ampl_spread1 = double(unique(Adetections(index_maxplot(max_2assess))));
Ampl_min = min(Ampl_spread1);
Ampl_tol = max(Ampl_spread1)-min(Ampl_spread1);
%%% for the xyz file store the data in the new matrix row/column
%disp('create an array with two columns and four rows:');
%disp('>> TolStores = x_min, x_tol; y_min, y_tol; z_min, z_tol; Ampl_min, Ampl_tol');
X = [x_min, x_tol];
Y = [y_min, y_tol];
Z = [z_min, z_tol];
A = [Ampl_min, Ampl_tol];
Tol_Stores = [X; Y; Z; A;];
%open Tol_Stores
Data2copy = Tol_Stores

Accepted Answer

Walter Roberson
Walter Roberson on 16 May 2022
You overwrite all of XDetections in every iteration of the first loop.
  2 Comments
Walter Roberson
Walter Roberson on 17 May 2022
You have a collection of point clouds. Currently you loop over the collection and extract some information and then throw the information away when you process the next point cloud.
Suppose that you keep the information. Can you just put all of the information from all of the pointClouds together as if it were one big pointCloud? Maybe, but that is certainly not obvious at the moment.
How about if you assign it to an array, using the point cloud number "index" as the index. Can we use columns of a rectangular array? We probably have no reason to expect that every point cloud is exactly the same size, so 2d array probably does not work unless you make sure to pad shorter entries.
So we probably are dealing with using a cell array. Or... you could just leave them in the existing struct
So you start processing with the first cloud. You record the index of the first location that has maximum Adetection. You do the same for each cloud, saving one value per cloud.
Now you want to index the XDetection according to information from the saved values. Your current code takes one cloud's XDetection and indexes it by the Adetection information across all of the clouds. Does that make sense?
If you were to save each XDetection instead of overwriting, then consider: suppose the first indexmax entry was 3. You have a collection of XDetection information for each cloud. How does that 3 fit into that? First point cloud so index the collection set by 1, getting the information for the first cloud, and index by that 3 from the a detection? Ok, but that would be a scalar... Are you wanting to accumulate that information over all of the clouds and use it to plot afterwards? That might be a reasonable thing to do... but if you think about it, it would make more sense to calculate the Adetection part first, and use it to index the other detections and store the resulting scalar values, instead of storing all of the XDetection for all clouds...

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!