0
votes

I am currently having issues with storing the values which I read from another text file using the textscan() function.

I am trying to use the NumPts as a counter so as to help me store the values of the number of variables from the dat file.

I am currently getting an error that states: Index exceeds matrix dimensions. Error in CorrectedWheelModelDataFromTxt (line 15) MyCellNumPts{1,1}= MyCellC{4,1};

Below is an excerpt of the code:

  MyCellXVal = cell(1,1000);
  MyCellYVal=  cell(1,1000);
  MyCellZVal=  cell(1,1000);
  MyCellNumPts = cell(1,1);
  NumPts=0;
  CountPts=1;

  MyCellC=cell(100,100);

  fileID = fopen('WheelReflectors.dat');
  MyCellC = textscan(fileID,'%d %d %d');
  fclose(fileID);

  MyCellNumPts{1,1}= MyCellC{4,1};
  NumPts = MyCellNumPts{1,1};
  while(CountPts<NumPts)

      MyCellXVal{1,CountPts} =C{CountPts,1};
      MyCellYVal{1,CountPts} =C{CountPts,2};
      MyCellZVal{1,CountPts} =C{CountPts,3};

      CountPts = CountPts +1;
  end

Below contains the data of the dat file: 130 40 70 270 40 70 200 40 0 3

I don't understand why I am getting the matrix dimension issue when I am just trying to store one value. Please advise me. Appreciate your assistance.

1

1 Answers

0
votes

Use dbstop if error to check what is happening, but basically:

First you create a 100 x 100 empty cell:

  `MyCellC=cell(100,100);`

But when you call textscan that is entirely overwritten.

  fileID = fopen('WheelReflectors.dat');
  MyCellC = textscan(fileID,'%d %d %d');
  fclose(fileID);

MyCellC is now size 1 x 3, and therefore you cannot access MyCellC{4,1} in the following line:

  MyCellNumPts{1,1}= MyCellC{4,1};

(It's not clear which number you want there, maybe myCellC{1}(4)?)

My suggestion: run up to fclose(fileID); from the command line, and then look at MyCellC and make sure you understand how the data is being organised as it is read in. You do not need any sort of loop here.