필터 지우기
필터 지우기

Trying to set up a matrix, getting error message

조회 수: 1 (최근 30일)
TheSaint
TheSaint 2024년 2월 2일
댓글: TheSaint 2024년 2월 2일
This is my current code, every time I attempt to run it I get an error message that says "Index in position 1 exceeds array bounds." How do I fix this?
Matrix = fscanf(fid, '%f', [3, 4]);
Unrecognized function or variable 'fid'.
w = Matrix(1,:);
t = Matrix(2, : );
g = Matrix(3, : );
  댓글 수: 1
VBBV
VBBV 2024년 2월 2일
% fid = 0;
% Matrix = fscanf(fid,'%f', [3, 4])
Matrix = [3, 4] % if this is your input Matrix read
Matrix = 1×2
3 4
size([3 4])
ans = 1×2
1 2
w = Matrix(1,:);
t = Matrix(2, : ); % here is the error where you try to access non-existent row
Index in position 1 exceeds array bounds. Index must not exceed 1.
g = Matrix(3, : );
you try to access non-existent row for the Matrix vector whose size consists of only 1 row

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

채택된 답변

Voss
Voss 2024년 2월 2일
Check the size of Matrix.
You may be able to use a different function to read your file, e.g., readmatrix instead of fopen/fscanf/fclose.
  댓글 수: 1
TheSaint
TheSaint 2024년 2월 2일
turns out my .txt file was messed up. Thanks anyway though.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2024년 2월 2일
You have accidentally created a variable named fscanf

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by