Problem with the find function
9 views (last 30 days)
Show older comments
Hi all,
I have a problem with my code and can't find what's wrong with it. Can someone help me?:(
I'm trying to sum the energy between two indexes,which is the interval of 10s.I use the find function but I get a message error:
??? Improper assignment with rectangular empty matrix.
Error in ==> testtaux2 at 29
klow(i)=find (temps >=t2(i),1,'first');
and here is my code:
clear all
close all
data2=load('SML64_long_AE_correct.txt');
data=load('trx9_SML64d_mod3.txt');
%data3=load('count.txt');
%t=data(:,1);
%def=data(:,12);
Q=data(:,11);
Ener=data2(:,14);
temps=data2(:,4);
def=data2(:,7);
defm=data(:,16);
amplitude=data2(:,12);
count=data2(:,9);
cumul_ener=data2(:,17);
dt=10;
k=0;
n=0;
for i=1:length(temps)-dt
t2(i)=temps(1)+n*dt;
t1(i)=t2(i)+dt;
n=n+1;
klow(i)=find (temps >=t2(i),1,'first');
kup(i)=find(temps >t1(i)+2*dt,1,'first');
dE(i)=sum(Ener((klow(i)):kup(i)));
t(i)=temps(klow(i))+temps(kup(i))/2;
k=k+1;
taux(k)=dE(i)/dt;
tt(k)=t(i);
end
%file = fopen('tauxfixe.txt','w');
% fprintf(file,' %f %f\n',taux(k),tt(k));
% fclose(file);
figure
plot(tt,taux)
hold on
Does anyone know what is wrong with my code?
Thank you very much for your help and sorry for my bad English !
0 Comments
Answers (3)
Roger Stafford
on 6 Apr 2014
I would guess offhand that when the 'find' function happens to come up empty at
klow(i)=find (temps >=t2(i),1,'first');
then matlab complains about trying to insert an empty array into a single space. If so, you will have to make some special provision for the empty case.
0 Comments
maxime bernard
on 7 Apr 2014
Thank you for your answer. I have tried to change it by replacing the "n" with "kk" index but I still get this messqge error.Do you know whatI can I do it? I have tried so many things and I always this problem.
dt=10;
k=0;
kk=1;
for i=1:length(temps)-dt
t1(i)=temps(kk);
t2(i)=t1(i)+dt;
klow(i)=find (temps >=t1(i),1,'first');
kup(i)=find(temps >t1(i) +dt,1,'first');
dE(i)=sum(Ener((klow(i)):kup(i)));
t(i)=temps(klow(i))+temps(kup(i))/2;
kk=kup(i);
k=k+1;
taux(k)=dE(i)/dt;
tt(k)=t(i);
end
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!