필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Counting the from when data changes to 0 then changes back to a number

조회 수: 1 (최근 30일)
Franchesca
Franchesca 2014년 5월 13일
마감: MATLAB Answer Bot 2021년 8월 20일
This is my code:
%% Import data
numfiles = 54; % number of excel files mydata=cell(numfiles,1); % defining size of mydata d=dir('Trial*.csv');
for i=7:length(mydata) % loop to import mutliple excel files
try
mydata{i} = xlsread(d(i).name); % import files into mydata
catch
disp([d(i).name 'read failed'])
end
myfilename = sprintf('Trial%02d.csv', i); % define file name
mydata{i} = xlsread(myfilename); % import files into mydata
%% Perfrom Calculations
%%Define variables
a= 9.81; % acceleration
fps = 250; % frames per second
%%Calculate Jump Height
no_of_zeros(i,1) = size(mydata{i,1},1) - nnz(mydata{i,1}(:,5)); %number of zeros
no_of_frames = (no_of_zeros(i,1)/4); % number of frames
time = ((no_of_frames/fps)/2); % time up
jumph(i,1)=((a*(time*time))/2); % jump height
Looking at the calculate jump height, it calculates correctly for the first 2 trials but then gives large over estimations for nealry all the other trails. It was a while ago I wrote this could someone clarify this line of code for me as this is where the trouble lies, I'm unsure with the ,1.
no_of_zeros(i,1) = size(mydata{i,1},1) - nnz(mydata{i,1}(:,5)); %number of zeros
  댓글 수: 4
Azzi Abdelmalek
Azzi Abdelmalek 2014년 5월 13일
Franchesca, zeros are also numbers. Your question and your comment are different. Do you need to count the number of zeros or how many time they switch from zero to non zero?
Franchesca
Franchesca 2014년 5월 13일
Sorry, from the numbers to zeros so count the number of zeros from the point in the column where the first zero appears to where that block of zeros ends.

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 5월 13일
편집: Azzi Abdelmalek 2014년 5월 13일
a=[1 1 0 0 4 5 0 0 7 4 7 0 0 0 7]
idx=[ 1 a~=0 1]
ii=strfind(idx,[1 0])
jj=strfind(idx,[0 1])
out=jj-ii

이 질문은 마감되었습니다.

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by