Index exceeds - for loop

1 visualización (últimos 30 días)
ReHa
ReHa el 30 de Oct. de 2019
Respondida: ReHa el 30 de Oct. de 2019
Hi, where is the Problem ("index exceeds matrix dimensions")?
With the "for loop" I want to calculate from Line 1 to Line 20
And the Calculation is from value 1 to value 100 each line.
What can I do, to fix the problem?
Many Thanks!!!
quest.jpg
  2 comentarios
Sai Bhargav Avula
Sai Bhargav Avula el 30 de Oct. de 2019
Can you provide the size of val.
ReHa
ReHa el 30 de Oct. de 2019
Editada: ReHa el 30 de Oct. de 2019
the size of val is 10201 x 1 and the data type is double

Iniciar sesión para comentar.

Respuesta aceptada

Turlough Hughes
Turlough Hughes el 30 de Oct. de 2019
The problem is you are specifying indices that dont exist in val. val is a column vector of 10201x1 values, i.e. 10201 rows and 1 column.
When you write val(i,1:100) matlab looks for row i and columns 1 to 100 of val, but there is only one column in your matrix val, hence your index exceeds your matrix dimensions.
  3 comentarios
Turlough Hughes
Turlough Hughes el 30 de Oct. de 2019
I would need to know more about what you are doing. You could convert your 10201 elements to a 101 by 101 array if you wanted...
val_array=reshape(val,[101 101]);
This takes the first 101 elements in column 1, the next 101 in column 2 and so on to column 101, or do you want to populate the new matrix row by row?
val_array=[reshape(val,[101 101])]';
However you will run into the same error as before on line 72 then. I suspect the overall issue lies further up in your code where you generated val.
ReHa
ReHa el 30 de Oct. de 2019
Okay, I will try "reshape".
My task: I have a Data file from a field measurement with an Fluxgate Magnetometer (the field: width 25 m and lengtg 50 m). This is an "X,Y,Z" File. X,Y are coordinates and Z the magnetic Data. The measurement contains 101 profile-lines with 101 measurement Points each line. Hence 10201 rows with Data. I´ve separteded the Data coulumn into a separate variable (val). Now, I have to correct these magnetic Data. It´s not necessary to correct the whole data of this field. I have to only correct some lines an some areas. Hence I'll use the for loop.

Iniciar sesión para comentar.

Más respuestas (1)

ReHa
ReHa el 30 de Oct. de 2019
I solved it with reshape ... Thanks at all !!!!

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by