Splitting a cell into two

조회 수: 2 (최근 30일)
Jake Bowd
Jake Bowd 2020년 5월 13일
편집: Ameer Hamza 2020년 5월 13일
Hi
I am interested in being able to extract one of two numbers that is in a cell and split by a semi-colon.
Image is attached indicating which I want to split.
Any help is greatly appreciated.
Many thanks in advance,
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2020년 5월 13일
Jake - have you already written the code to read the data from the Excel file? If so, are you just reading in the column of interest or all of the columns? Whether you have read it one or all, what is the data type for that column that you wish to split on - is the data being saved as a char/string?
Jake Bowd
Jake Bowd 2020년 5월 13일
Hi Geoff,
I have written the code to read a number of 'trials' in from a file name '.mot'. Essentially reading in a large structure from something similar to Excel.
I have now established how to split the data, however when I put into a for loop, only the last loop is being saved. Below is the script:
for i=1:nwalks
[Maxpeaks]=findpeaks(Results.Knee_Add_R_Torque(i).waveforms(60:100),'SortStr','descend');
Threshold=Maxpeaks(1,1)*Thold; %Determines the threshold for the findpeaks function
[Results.Knee_Add_R_Torque(i).MaxPeaks, Results.Knee_Add_R_Torque(i).Peaklocationpercent]=findpeaks(Results.Knee_Add_R_Torque(i).waveforms,'MinPeakHeight',Threshold,'MinPeakDistance',width);
end
for i=1:nwalks
Results.Ave=Results.Knee_Add_R_Torque(i).MaxPeaks';
end
Any ideas why the two outputs are being replaced to the last loop?

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

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 5월 13일
편집: Ameer Hamza 2020년 5월 13일
You need to assign values to elements in a cell array to prevent them from being overwritten
Results.Ave = cell(1,nwalks); % optional initialization for faster execution
for i=1:nwalks
Results.Ave{i}=Results.Knee_Add_R_Torque(i).MaxPeaks';
end
Or maybe you are trying to create a single matrix with the values of MaxPeaks. In that case try
Results.Ave = [Results.Knee_Add_R_Torque.MaxPeaks].';

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by