- 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:
How to loop through an array that contains multiple arrays within the cells
7 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Jan
on 20 Aug 2017
Edited: Jan
on 20 Aug 2017
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.
See Also
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!