Filter löschen
Filter löschen

Trying to set up a matrix, getting error message

1 Ansicht (letzte 30 Tage)
TheSaint
TheSaint am 2 Feb. 2024
Kommentiert: TheSaint am 2 Feb. 2024
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 Kommentar
VBBV
VBBV am 2 Feb. 2024
% 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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Voss
Voss am 2 Feb. 2024
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 Kommentar
TheSaint
TheSaint am 2 Feb. 2024
turns out my .txt file was messed up. Thanks anyway though.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 2 Feb. 2024
You have accidentally created a variable named fscanf

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by