Splitting a cell into two

1 view (last 30 days)
Jake Bowd
Jake Bowd on 13 May 2020
Edited: Ameer Hamza on 13 May 2020
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 Comments
Geoff Hayes
Geoff Hayes on 13 May 2020
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 on 13 May 2020
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?

Sign in to comment.

Accepted Answer

Ameer Hamza
Ameer Hamza on 13 May 2020
Edited: Ameer Hamza on 13 May 2020
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].';

More Answers (0)

Categories

Find more on Data Type Conversion 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!