MATLAB Answers

Index in position 2 exceeds array bounds (must not exceed 1). Error in dlmread (line 159) result= result(:,1:ncols);

조회 수: 3(최근 30일)
anshu rai
anshu rai 2020년 11월 19일
편집: Jon 2020년 11월 20일
In my try.txt file, there are 9 columns with 300000 float values(300 times 1000 samples). In between every 1000 samples and in the beginning, there is some text written which I tried to skip by incrementing i appropriately. My aim is to find variance of every column with 1000 samples and repeat till the end(i.e will 300000), which will enable me to get 300 by 9 matrix.
clc
clear
close all
file=('try.txt');
%M = dlmread(testtime.txt,' ',50,50)
i=23;
%variences=zeros(300,1);
for k=1:300
j=i+1000-1;
A = dlmread(file,' ',[i 0 j 8]);
variences(k)= var(A(:,3));
i=i+1000+11;
end
variences';
plot(1:300,variences)
variences=variences';
Please help me asap. I am new to matlab

답변(1개)

Jon
Jon 2020년 11월 19일
You may have other problems too, but I noticed that since i does not change inside of your loop, you always read from the same starting row. Note that in your call i which is the first (starting row) does not change, but you ending row j does. Instead I would think you want something more like
A = dlmread(file,' ',[j 0 j+1000 8]);
  댓글 수: 5
Jon
Jon 2020년 11월 20일
If this still is not working then please attach a portion of your data file with the first couple of blocks of data (so about 2000+ rows, not too big but big enough to see exactly what is in there and the repetitive pattern)

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by