How to load tabular data correctly and make this code work?
显示 更早的评论
Hello, everyone. I have an m-file (named exercise_spatreg3) and a .txt file with tabular data (exercise_data333) to be processed in MatLab for calculating ρ values as part of a spatial regression task. The problem is that the provided code (please, see the code below) does not seem to run correctly and error messages show up.
%*********Spatial regression******** %***This program calculates a new value (z*) for each value (zi)in a table and %***account for all other values (zj). These other values (zj)are weighted with the %****squared distance (1/d^2). %***In this version, we only use values that are within a specific radius %***chosen by the user. e.g "d<30" %***The program calculates new z for the same number of columns that the input file has got. %*** % % % % % clear format long % load C:\tempdata\data333.txt col=0; raa=0.05; d=0; c=0; n=0; w=0; b=0; data4=zeros(220,10);
for col=3:12
for i=1:220
b=0;
c=0;
for j=1:220
if i~=j
d=sqrt((data333(i,1)-data333(j,1))^2+(data333(i,2)-data333(j,2))^2);
if d<30
c=(1/(d^2))*data333(j,col);
b=b+c;
else
end
end
end
x=data333(i,col) - (raa * b);
n=i;
data4(i,col)= x;
data4(i,1)=n;
end
dlmwrite('trash.txt',data4,'\t') dlmwrite('data333-100spreg2-raa05.txt',data4,'\t') end
One of the most common messages is that there is a problem with parantheses in Line 94/93/etc. The error message always leads to line
d=sqrt((data333(i,1)-data333(j,1))^2+(data333(i,2)-data333(j,2))^2);
I am a new user of this software and struggle with loading data and executing calculations in this exercise. Maybe you could help me with getting this code to work as it is just a part of the bigger process and not much time is left. Thank you for any suggestions.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!