0
votes

I have a .txt (220 rows * 12 cols, first row text, rest of the file is decimal numbers) file, first I converted it to a table: T = readtable('xxx.txt','Delimiter','\t') and then saved T to .mat form.

Then I ran these codes:

>> load T.mat
>> 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((T(i,1)-T(j,1))^2+(T(i,2)-T(j,2))^2);
            if d<30              
            c=(1/(d^2))*T(j,col);
            b=b+c;
           else
           end

    end
  end

x=T(i,col) - (raa * b);
n=i;

data4(i,col)= x;
  data4(i,1)=n;

   end

    %   dlmwrite('trash.txt',data4,'\t')
   dlmwrite('T-100spreg2-raa05.txt',data4,'\t')    
  end

I got an error message:

Error: undefined function 'minus' for input arguments of type table.

My questions are:

  1. why when I checked the size of T I got ans=1 1, why not ans=220 12?

  2. why I got this error message?

  3. If I shouldn't use table T directly in the code, then I need to convert it to an array. I used A=table2array('T') and got: Error: Cell contents reference from a non cell array object Error in table2array (line 27) a = t{:,:}; Could it be I did something wrong from the first step i.e. convert .txt to table (thus I got ans=1 1 but not 220 12)?

1
It would be easier to figure out the errors if this was a reproducible example. Could you include the creation of a dummy table instead of just the load statement? - Dennis Jaheruddin
Why use a table at all? I would think a matrix would be a lot simpler. You should be able to directly read the file into a matrix rather than a table. - David K
As @DavidK mentions, it may indeed not be neccesary to use a table. Have a look at doc dlmread. - Dennis Jaheruddin
@DavidK As long as I use dlmred, I got an error message to say it is problematic when reading numbers==>x y DEM asp grad DAI2 HI VI SLI2 Yield DAI1 SLI1\n. This is the first row of my .txt file. - ZhangYao Jiayin
Not sure why you're getting an error. Try fscanf and textscan as well. I would just skip the first row and start on the numbers. - David K

1 Answers

0
votes

This is only a partial answer, but it should explain why you got the error when trying to use table2array.

The input of the relevant function should not be the name of the table, but rather the table itself. As such you should replace:

A=table2array('T')

by

A=table2array(T)

Perhaps this is enough to help you on your way and figure out the other issues as well.