Index exceeds - for loop

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 Comments

Can you provide the size of val.
ReHa
ReHa on 30 Oct 2019
Edited: ReHa on 30 Oct 2019
the size of val is 10201 x 1 and the data type is double

Sign in to comment.

 Accepted Answer

Turlough Hughes
Turlough Hughes on 30 Oct 2019

0 votes

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 Comments

ReHa
ReHa on 30 Oct 2019
Okay, I understand the problem. What can I do, to fix the problem? Convert the vector? How?
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 on 30 Oct 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.

Sign in to comment.

More Answers (1)

ReHa
ReHa on 30 Oct 2019

0 votes

I solved it with reshape ... Thanks at all !!!!

Products

Asked:

on 30 Oct 2019

Answered:

on 30 Oct 2019

Community Treasure Hunt

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

Start Hunting!