How to loop through an array that contains multiple arrays within the cells

7 views (last 30 days)
Hi,
I have created an array that has arrays within it as the excel sheet that I am reading it in from has 10 worksheets from which data must be used.
The aim of what I am doing is to find the maximum value for torque from a table in excel that is given to me, the data is for a pedal stroke and I wish to find the maximum torque applied turning the crank arm in one full revolution of a pedal (therefore 360 results), then once I have found the torque value, a second bit of code in which the degrees this torque is applied at is recorded. The torque is in column F from row 10 to 370 of worksheet 1 to 10 and the degrees is in column A from row 10 to 370 of the same worksheets.
The code to read in the data is as follows.
addpath('*file_location*'); % create a file path to folder containing tests
[type,sheetname]=xlsfinfo('*file*');
m=size(sheetname,2);
data=cell(1,m);
for(i=1:1:m);
Sheet=char(sheetname(1,i));
data{i}=xlsread('*file*',Sheet);
end
The code I have come up with is wrong and not sure if I am even going in the right direction or not? I have not attempted the second step of identifying the angle where the max torque is achieved as I have still not done the first part.
i
for i=data(1:1:10); % loops ten 10 times through each cyclist once
torquevalues=[]; % empty matrix for torque values
tN0=i(10:370,5); % Numbers in excel which relate to torque
tMax=max(tN0); % max number in torque numbers
end
Any help that can be provided is greatly appreciated, Ive tried to find this problem online with little success as well so if I could be pointed in the right direction as well then this would help, or if you need more information to try and help me out then more than happy to provide.
Thank you

Answers (1)

Jan
Jan on 20 Aug 2017
Edited: Jan on 20 Aug 2017
  • Do not add the folder of the data file to Matlab's path. Use absolute file names instead.
  • You do not need the names of the sheet, if you import all of them. Use the sheet indices is easier:
file = fullfile('*file_location*', '*file*');
data = cell(1,m);
for iSheet = 1:m
data{iSheet} = xlsread(file, iSheet);
end
It is not clear, what the 2nd part should do. Please try it at first and fix as many problems as you can. Then post the code again here.
  1 Comment
Toby Reynolds-Cotterill
Toby Reynolds-Cotterill on 21 Aug 2017
Hi Jan,
Thanks for the reply.
The second part has the aim of locating where the maximum value is. Then once the maximum for each column has been found locating the angle of rotation around a crank of a bicycle where this occurred.
I have done the first section of the second part however the second section is confusing me, I've tried to use the find function but this is wrong?
Essentially the aim of the second section is to find the location of the maximum values acquired in the first section.
below is the code for the first section:
i <- ignore this
tTest=cell2mat(data); % convert cell array to matrix
u=tTest(10:370,5:13:122); % reads torque data for all ten cyclists in a loop and enters into an array
uA=u(:,1:1:10); % loop from column 1 all rows along to the last column
tN0=max(uA); % max value in the column for each
tMaxR=tN0; % simplify result
The maximum values are located in a 361x10 matrix as I convert the cell array to a matrix to make it easier to loop. Each column represents a different cyclist, therefore 10 cyclists in total.
The results (the maximum values) are put into a 10x1 matrix.
I need to find the location of the cells so can find the angle of the crank at the max torque.
Once I have the location I can apply it to the original column for the angle and find the angle, unless you can think of a better way.
This second section of finding the maximum values is really stumping me, any help is appreciated.

Sign in to comment.

Categories

Find more on Data Import from MATLAB 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!