How to fix the Dot indexing is not supported for variables of this type error?

1 view (last 30 days)
clc;
clear all;
close all;
format long g;
load('dtm.mat')
dist_hwZ= repmat([0:100:(size(Z,1)-1)*100]',1,size(Z,2));
dist_rwZ = (repmat([0:100:(size(Z,2)-1)*100]',1,size(Z,1),1))';
thinned_dist_hwZ = dist_hwZ(1:5:end,1:5:end);
thinned_dist_rwZ = dist_rwZ(1:5:end,1:5:end);
% thinned_dist_rwZ = (thinned_dist_rwZ)';
thinned_Z = Z(1:5:end,1:5:end);
current_dist = NaN(size(thinned_dist_hwZ));
assigned_dist = current_dist; %line23
for i = 1:length(thinned_dist_hwZ,1)
for j=1:length(thinned_dist_hwZ,2)
current_dist = sqrt(((thinned_dist_hwZ-thinned_dist_hwZ(i,j)).^2 + (thinned_dist_rwZ-thinned_dist_rwZ(i,j)).^2)');
%compute distance not height % sqrt delx^2 dely^2 approx 70 km distance of hypotenous
if i==1 && j==1
max_dist=max(max(current_dist));
end
for k =1:round(max_dist/1e4)
if k==1
assigned_dist(current_dist<=k*1e4)=k;
else
assigned_dist(current_dist<=k*1e4 & current_dist>(k-1)*1e4)=k;
end
prod_Z = Z(assigned_dist==k).*Z(i,j);
eval(['allClasses.i' num2str(i) ['.j' num2str(j) ['.k' num2str(k) '=prod_Z' ]]]);
if k==1
eval(['K1:prod_Z_' [num2str(i) '_' num2str(j)] '=prod_Z']);
elseif k==2
eval(['K2:prod_Z_' [num2str(i) '_' num2str(j)] '=prod_Z']);
elseif k==3
eval(['K3:prod_Z_' [num2str(i) '_' num2str(j)] '=prod_Z']);
elseif k==4
eval(['K4:prod_Z_' [num2str(i) '_' num2str(j)] '=prod_Z']);
elseif k==5
eval(['K5:prod_Z_' [num2str(i) '_' num2str(j)] '=prod_Z']);
elseif k==6
eval(['K6:prod_Z_' [num2str(i) '_' num2str(j)] '=prod_Z']);
else
eval(['K7:prod_Z_' [num2str(i) '_' num2str(j)] '=prod_Z']);
end
end
imagesc(current_dist)
end
end
fns = fieldnames(k);
  1 Comment
Stephen23
Stephen23 on 11 Jun 2021
Edited: Stephen23 on 11 Jun 2021
"How to fix the Dot indexing is not supported for variables of this type error?"
Better code. Your design forces you into writing slow, inefficient, complex code which is liable to bugs and difficult to debug. This is exactly what you are facing now. You can avoid this by designing your data better and using more reliable and efficient code paradigms:
For example, this line:
eval(['allClasses.i' num2str(i) ['.j' num2str(j) ['.k' num2str(k) '=prod_Z' ]]]);
what is the point in having these multiple nested horizontal concatenations? Why do you need superfluous EVAL when fieldnames can be specified directly?:
Even better would be to avoid forcing meta-data into fieldnames (slow) and use arrays instead (fast, could be numeric or container class, e.g. structure). Bad code also makes it easy to hide bugs:
K7:prod_Z_1_1 = prod_Z
^ What do you expect this syntax to achieve?
Better data design allows for simpler, more efficient code, with fewer bugs.

Sign in to comment.

Answers (1)

KSSV
KSSV on 11 Jun 2021
Edited: KSSV on 11 Jun 2021
Replace (i.j) with (i,j). There is . (dot) between i and j; replace it with comma.
it seems a typo error.
  4 Comments
vimal kumar chawda
vimal kumar chawda on 11 Jun 2021
I have edited the code with update as per your comment but still
Error using length
Too many input arguments.
Where it is the problem? Can you please update me?
KSSV
KSSV on 11 Jun 2021
REad the documentation of the respective function.
It should
length(thinned_dist_hwZ,1)
Replaced with
length(thinned_dist_hwZ)

Sign in to comment.

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!