Trouble reading in multiple xls files

clear all; % clears all variables from your workspace
close all; % closes all figure windows
clc; % clears command window
%%define number of trials
njump=81;
[1] input variables of trial data
%%%%%%%%%%%%%%%%%%%%%
%read in excel data in CSV format
for i=1:njump
data1=xlsread('Trial%i.csv','Trial%i','A1:E7000'); % jump data
end
^^^^^ this is what I have written, however it will not read in all of the data that I need. I have 81 trials but it will not read them in even when I have put a loop in. I am quite a novice in matlab and I don't understand what I am doing wrong. Can anyone help?

 Accepted Answer

data1 is overwriten each loop, use
for i=1:njump
data1{i}=xlsread(sprintf('Trial%i.csv',i),sprintf('Trial%i',i),'A1:E7000'); % jump data
end
If you want to clear all workspace variables use
clear
% without all

10 Comments

I have just typed that exact code in, however this does not solve it.
I want to be able to read in all xlsx files from trial08-81
for i=1:njump
data1{i}=xlsread(sprintf('Trial%i.csv',i),sprintf('Trial%i',i),'A1:E7000'); end
I have now written this:
for i=1:njump
x=sprintf('Trial%i.csv',i),sprintf('Trial%i',i),'A1:E7000';% jump data
data{i}=xlsread(x);
end
from your help. However it does not want to read the trial numbers which are trial01,trial02 etc. because of the zero?
What trial01 represent in your file?
data that i'm trying to import but it says it cannot find it, it is in all the same folders
for i=1:njump
x=sprintf('Trial%i.csv',i);
data{i}=xlsread(x,'A1:E7000');
end
thank you for your help it ended up being this:
for i=1:njump; x=sprintf('Trial%02d.csv',i),sprintf('Trial%02d',i),'A1:E7000';% jump data data{i}=xlsread(x,'A1:E7000'); end
Hi,
I've tried to use this same code for my similair problem. However it doesn't seem to bring in any data.
My variables read:
Ans: 'A1:E7000', when you go into it it just says A!:E7000
data: cell, which when you go into just has 81 cells saying 6004x5 double
i: 81, when you go into it just says 81
njump: 81, when you go into it just says 81
x: 'Trial81.csv', when I go into this it just says 'Trial81.csv'
Is this what I am meant to have/is this what you got?
What did you do next?
Thanks
Try using all 3 outputs of xlsread()
[numbersOnly, textOnly, everything] = xlsread(filename);
What shall I put this instead of?
This is the code I am trying currently:
:

Sign in to comment.

Tags

Asked:

on 12 May 2014

Commented:

BOB
on 16 May 2014

Community Treasure Hunt

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

Start Hunting!