subscripted assignment dimension mismatch
이전 댓글 표시
I keep experiencing an error - subscripted assignment dimension mismatch, within the matrix(chan,:)=eeg can anyone help?
chan=0;
while ~feof(fid); %loop to read lines into matrix
chan=chan+1;
tline = fgetl(fid);
disp(tline); %display the data to be put into the matrix to check it has been read
eeg=sscanf(tline,'%f');
matrix(chan,:)=eeg;
end
답변 (2개)
Star Strider
2014년 12월 13일
I can’t be certain what the precise problem may be without seeing more of your code. If you preallocated ‘matrix’ to be a scalar or an empty matrix, that could potentially throw that error.
The usual ‘fix’ I suggest in such situations is to make a cell array out of ‘matrix’ to see if that solves the immediate problem:
matrix{chan} = eeg;
You can always go back to it later to parse your data.
Guillaume
2014년 12월 13일
For the line
matrix(chan, :) = eeg
to work, matrix must have as many columns as there are values in eeg. If that is not the case, then you'll get a subscripted assignment mismatch error. With your code, eeg has as many values as sscanf can decode from a line, which may or may not be the same number as the number of columns of matrix.
So, do you expect the same numbers of values on each line of your text file? If so, what do you want to happen when that is not the case? An error? Skip the line? Fill missing values with NaN and discard overflow? Something else?
If you don't expect the same number of values in each line, then you can't store them in a matrix. You could use a cell array instead.
카테고리
도움말 센터 및 File Exchange에서 EEG/MEG/ECoG에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!