Index exceeds - for loop

조회 수: 1 (최근 30일)
ReHa
ReHa 2019년 10월 30일
답변: ReHa 2019년 10월 30일
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
Sai Bhargav Avula
Sai Bhargav Avula 2019년 10월 30일
Can you provide the size of val.
ReHa
ReHa 2019년 10월 30일
편집: ReHa 2019년 10월 30일
the size of val is 10201 x 1 and the data type is double

댓글을 달려면 로그인하십시오.

채택된 답변

Turlough Hughes
Turlough Hughes 2019년 10월 30일
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
Turlough Hughes
Turlough Hughes 2019년 10월 30일
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 2019년 10월 30일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

ReHa
ReHa 2019년 10월 30일
I solved it with reshape ... Thanks at all !!!!

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by