How to execute a function for several different range from a same array?

2 visualizaciones (últimos 30 días)
Yanjika O
Yanjika O el 19 de Mayo de 2020
Editada: Sindar el 19 de Mayo de 2020
Hello people,
I have this excel data sheet that I imported to the matlab in an array "s".
S=readtable('safe1.xlsx','Sheet','ezOutput','Range','M1:M23026');
s=table2array(S)';
out=s[1693:2203 4001:4510];
%FIND THE DISTANCE VALUE BELOW 6 USING LOGICAL INDEXING
for j=1:length(out);
idx=s<5;
ii1=strfind([0 idx 0],[0 1]);
ii2=strfind([0 idx 0],[1 0])-1;
end
%the frame rate of the video is 30, thus 30 indicates 1 sec of video
ii=(ii2-ii1+1)>=30; %define the minimum duration which the speed value goes under 10 for 30 frames
out=arrayfun(@(x,y)s(x:y),ii1(ii),ii2(ii),'un',0); %wrap the result of each function call into a cell
n=cellfun(@numel,cell(out));%finding number of element in cells of an array
for n=n(:,:)'
fd=(n/30);%finding time duration of freezing based on the number of elements in array cell
f=sum(fd);
disp(f)
end
col_head={'Conditioning','Freezing,(sec)','Total freezing,(sec)'};
row_head=(1:10)';
xlswrite('safe1.xlsx',col_head,'Sheet2','A1:C1');
xlswrite('safe1.xlsx',row_head,'Sheet2','A2:A11');
I wanted extract or bin my data before but recently I have found out that I could specify the range of my data as follows:
out=s[1693:2203 4001:4510]; however it shows an error that says:
Error: File: Untitled Line: 7 Column: 6. Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
Plus I want to repeat the code below determining whether the range of an array elements were under 5 and if so was it under 5 for 30 frames and if so calculating the number of the frames and write it out to different excel sheet.
Please kindly give your suggestions.
Thank you in advance.
  1 comentario
Sindar
Sindar el 19 de Mayo de 2020
Editada: Sindar el 19 de Mayo de 2020
To index a variable, you need parenthesis. The brackets allow you to define a set of indices that contains multiple groups.
out=s(1693:2203);
out=s([1693:2203 4001:4510]);
You can probably access the data directly from the table. In the case of tables (and cell arrays), use {} to access data:
out=S{[1693:2203 4001:4510],1};

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by